src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php
private function checkArrayStructure(array $invalidCodes, int $searchPos): void
    {
        // Rename the var to get more readable code.
        $remainingInvalidCodes = $invalidCodes;
        unset($invalidCodes);

        foreach ($remainingInvalidCodes as $nextInvalidCodeIndex => $nextInvalidCode) {
            $foundTokenPos = TokenHelper::findNextEffective($this->getFile(), $searchPos);
            $foundToken = $this->tokens[$foundTokenPos];

            // We can stop the search, if there is no invalid code.
            if ($foundToken['code'] !== $nextInvalidCode) {
                break;
            }

            // Check the next possible token
            $searchPos = $foundTokenPos + 1;
            unset($remainingInvalidCodes[$nextInvalidCodeIndex]);
        }

        $matchedEveryInvalidCode = !$remainingInvalidCodes;

        $this->file->recordMetric(
            $searchPos,
            'Invalid array comparison',
            $matchedEveryInvalidCode ? 'yes' : 'no'
        );

        if ($matchedEveryInvalidCode) {
            throw (new CodeError(static::CODE_EMPTY_ARRAY, self::MESSAGE_EMPTY_ARRAY, $searchPos));
        }
    }
private function checkArrayStructure(array $invalidCodes, int $searchPos): void
    {
        // Rename the var to get more readable code.
        $remainingInvalidCodes = $invalidCodes;
        unset($invalidCodes);

        foreach ($remainingInvalidCodes as $nextInvalidCodeIndex => $nextInvalidCode) {
            $foundTokenPos = TokenHelper::findNextEffective($this->getFile(), $searchPos);
            $foundToken = $this->tokens[$foundTokenPos];

            // We can stop the search, if there is no invalid code.
            if ($foundToken['code'] !== $nextInvalidCode) {
                break;
            }

            // Check the next possible token
            $searchPos = $foundTokenPos + 1;
            unset($remainingInvalidCodes[$nextInvalidCodeIndex]);
        }

        $matchedEveryInvalidCode = !$remainingInvalidCodes;

        $this->file->recordMetric(
            $searchPos,
            'Invalid array comparison',
            $matchedEveryInvalidCode ? 'yes' : 'no'
        );

        if ($matchedEveryInvalidCode) {
            throw (new CodeError(static::CODE_EMPTY_ARRAY, self::MESSAGE_EMPTY_ARRAY, $searchPos));
        }
    }
private function checkArrayStructure ( array $ invalidCodes , int $ searchPos ) : void { // Rename the var to get more readable code. $ remainingInvalidCodes = $ invalidCodes ; unset ( $ invalidCodes ) ; foreach ( $ remainingInvalidCodes as $ nextInvalidCodeIndex => $ nextInvalidCode ) { $ foundTokenPos = TokenHelper :: findNextEffective ( $ this -> getFile ( ) , $ searchPos ) ; $ foundToken = $ this -> tokens [ $ foundTokenPos ] ; // We can stop the search, if there is no invalid code. if ( $ foundToken [ 'code' ] !== $ nextInvalidCode ) { break ; } // Check the next possible token $ searchPos = $ foundTokenPos + 1 ; unset ( $ remainingInvalidCodes [ $ nextInvalidCodeIndex ] ) ; } $ matchedEveryInvalidCode = ! $ remainingInvalidCodes ; $ this -> file -> recordMetric ( $ searchPos , 'Invalid array comparison' , $ matchedEveryInvalidCode ? 'yes' : 'no' ) ; if ( $ matchedEveryInvalidCode ) { throw ( new CodeError ( static :: CODE_EMPTY_ARRAY , self :: MESSAGE_EMPTY_ARRAY , $ searchPos ) ) ; } }
Search starting with the given search pos for the invalid codes in consecutive order.

@throws CodeError Contains the error message if there is an invalid array check.

@param array $invalidCodes
@param int $searchPos

@return void
Search starting with the given search pos for the invalid codes in consecutive order .