PHPSA\Analyzer\Pass\Statement\YodaCondition::pass PHP Method

pass() public method

public pass ( $stmt, Context $context ) : boolean
$stmt
$context PHPSA\Context
return boolean
    public function pass($stmt, Context $context)
    {
        $condition = $stmt->cond;
        if ($stmt instanceof Stmt\For_ && count($stmt->cond) > 0) {
            // For is the only one that has an array as condition
            $condition = $condition[0];
        }
        if ($condition instanceof Equal || $condition instanceof NotEqual || $condition instanceof Identical || $condition instanceof NotIdentical) {
            if ($condition->left instanceof Scalar && $condition->right instanceof Variable) {
                $context->notice('yoda_condition', 'Avoid Yoda conditions, where constants are placed first in comparisons', $stmt);
                return true;
            }
        }
        return false;
    }
YodaCondition