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;
}