src/ETSGlobalCodingStandard/Helpers/ArrayHelper.php
/**
     * Counts the number of elements in the array.
     *
     * @param int   $arrayPointer The pointer to the array.
     * @return int                The size of the array.
     */
Counts the number of elements in the array.
@param int   $arrayPointer The pointer to the array.
@return int                The size of the array.
Counts the number of elements in the array . @param int $arrayPointer The pointer to the array . @return int The size of the array .
public static function count(File $phpcsFile, int $arrayPointer): int
    {
        $tokens = $phpcsFile->getTokens();
        $array = $tokens[$arrayPointer];
        $closeBracketPointer = $array['bracket_closer'];
        $count = 0;
        $currentPointer = $arrayPointer + 1;
        while ($currentPointer < $closeBracketPointer) {
            $nextDelimiterPointer = $phpcsFile->findEndOfStatement($currentPointer, [T_DOUBLE_ARROW]);
            if (!$nextDelimiterPointer || $currentPointer === $nextDelimiterPointer) {
                break;
            }
            $item = TokenHelper::findNextEffective($phpcsFile, $currentPointer, $nextDelimiterPointer);
            if (!$item) {
                break;
            }
            $count++;
            if ($nextDelimiterPointer === $closeBracketPointer) {
                break;
            }
            $currentPointer = $nextDelimiterPointer + 1;
        }
        return $count;
    }
public static function count ( File $ phpcsFile , int $ arrayPointer ) : int { $ tokens = $ phpcsFile -> getTokens ( ) ; $ array = $ tokens [ $ arrayPointer ] ; $ closeBracketPointer = $ array [ 'bracket_closer' ] ; $ count = 0 ; $ currentPointer = $ arrayPointer + 1 ; while ( $ currentPointer < $ closeBracketPointer ) { $ nextDelimiterPointer = $ phpcsFile -> findEndOfStatement ( $ currentPointer , [ T_DOUBLE_ARROW ] ) ; if ( ! $ nextDelimiterPointer || $ currentPointer === $ nextDelimiterPointer ) { break ; } $ item = TokenHelper :: findNextEffective ( $ phpcsFile , $ currentPointer , $ nextDelimiterPointer ) ; if ( ! $ item ) { break ; } $ count ++ ; if ( $ nextDelimiterPointer === $ closeBracketPointer ) { break ; } $ currentPointer = $ nextDelimiterPointer + 1 ; } return $ count ; }
Counts the number of elements in the array.
Counts the number of elements in the array .
// Reached the end of the array