src/Fixer/ControlStructure/YodaStyleFixer.php
private function getCompareFixableInfo(Tokens $tokens, $index, $yoda)
    {
        $left = $this->getLeftSideCompareFixableInfo($tokens, $index);
        $right = $this->getRightSideCompareFixableInfo($tokens, $index);

        if ($yoda) {
            $expectedAssignableSide = $right;
            $expectedValueSide = $left;
        } else {
            if ($tokens[$tokens->getNextMeaningfulToken($right['end'])]->equals('=')) {
                return null;
            }

            $expectedAssignableSide = $left;
            $expectedValueSide = $right;
        }

        if (
            // variable cannot be moved to expected side
            !(
                !$this->isVariable($tokens, $expectedAssignableSide['start'], $expectedAssignableSide['end'], false)
                && !$this->isListStatement($tokens, $expectedAssignableSide['start'], $expectedAssignableSide['end'])
                && $this->isVariable($tokens, $expectedValueSide['start'], $expectedValueSide['end'], false)
            )
            // variable cannot be moved to expected side (strict mode)
            && !(
                $this->configuration['always_move_variable']
                && !$this->isVariable($tokens, $expectedAssignableSide['start'], $expectedAssignableSide['end'], true)
                && !$this->isListStatement($tokens, $expectedAssignableSide['start'], $expectedAssignableSide['end'])
                && $this->isVariable($tokens, $expectedValueSide['start'], $expectedValueSide['end'], true)
            )
        ) {
            return null;
        }

        return [
            'left' => $left,
            'right' => $right,
        ];
    }
private function getCompareFixableInfo(Tokens $tokens, $index, $yoda)
    {
        $left = $this->getLeftSideCompareFixableInfo($tokens, $index);
        $right = $this->getRightSideCompareFixableInfo($tokens, $index);

        if ($yoda) {
            $expectedAssignableSide = $right;
            $expectedValueSide = $left;
        } else {
            if ($tokens[$tokens->getNextMeaningfulToken($right['end'])]->equals('=')) {
                return null;
            }

            $expectedAssignableSide = $left;
            $expectedValueSide = $right;
        }

        if (
            // variable cannot be moved to expected side
            !(
                !$this->isVariable($tokens, $expectedAssignableSide['start'], $expectedAssignableSide['end'], false)
                && !$this->isListStatement($tokens, $expectedAssignableSide['start'], $expectedAssignableSide['end'])
                && $this->isVariable($tokens, $expectedValueSide['start'], $expectedValueSide['end'], false)
            )
            // variable cannot be moved to expected side (strict mode)
            && !(
                $this->configuration['always_move_variable']
                && !$this->isVariable($tokens, $expectedAssignableSide['start'], $expectedAssignableSide['end'], true)
                && !$this->isListStatement($tokens, $expectedAssignableSide['start'], $expectedAssignableSide['end'])
                && $this->isVariable($tokens, $expectedValueSide['start'], $expectedValueSide['end'], true)
            )
        ) {
            return null;
        }

        return [
            'left' => $left,
            'right' => $right,
        ];
    }
private function getCompareFixableInfo ( Tokens $ tokens , $ index , $ yoda ) { $ left = $ this -> getLeftSideCompareFixableInfo ( $ tokens , $ index ) ; $ right = $ this -> getRightSideCompareFixableInfo ( $ tokens , $ index ) ; if ( $ yoda ) { $ expectedAssignableSide = $ right ; $ expectedValueSide = $ left ; } else { if ( $ tokens [ $ tokens -> getNextMeaningfulToken ( $ right [ 'end' ] ) ] -> equals ( '=' ) ) { return null ; } $ expectedAssignableSide = $ left ; $ expectedValueSide = $ right ; } if ( // variable cannot be moved to expected side ! ( ! $ this -> isVariable ( $ tokens , $ expectedAssignableSide [ 'start' ] , $ expectedAssignableSide [ 'end' ] , false ) && ! $ this -> isListStatement ( $ tokens , $ expectedAssignableSide [ 'start' ] , $ expectedAssignableSide [ 'end' ] ) && $ this -> isVariable ( $ tokens , $ expectedValueSide [ 'start' ] , $ expectedValueSide [ 'end' ] , false ) ) // variable cannot be moved to expected side (strict mode) && ! ( $ this -> configuration [ 'always_move_variable' ] && ! $ this -> isVariable ( $ tokens , $ expectedAssignableSide [ 'start' ] , $ expectedAssignableSide [ 'end' ] , true ) && ! $ this -> isListStatement ( $ tokens , $ expectedAssignableSide [ 'start' ] , $ expectedAssignableSide [ 'end' ] ) && $ this -> isVariable ( $ tokens , $ expectedValueSide [ 'start' ] , $ expectedValueSide [ 'end' ] , true ) ) ) { return null ; } return [ 'left' => $ left , 'right' => $ right , ] ; }
@param Tokens $tokens
@param int    $index
@param bool   $yoda

@return null|array
@param Tokens $tokens @param int $index @param bool $yoda