[Analyzer] Avoid yoda conditions
ddmler opened this issue · 1 comments
ddmler commented
Simple Task: Statement Analyzer for conditions, detects:
if (true == $someParameter) {
}
How to do it:
- Create Analyzer (you can use this one as a template: https://github.com/ovr/phpsa/blob/master/src/Analyzer/Pass/Statement/AssignmentInCondition.php )
and register it to the same things. Now:
Check that $condition instanceof Expr\BinaryOp\ {Equal, NotEqual, Identical, NotIdentical}
If yes check that:
$condition->left->isScalar()
$condition->right instanceof Expr\Variable
If yes write a nice notice message, else return false.
- Add it to PHPSA\Analyzer\Factory (registerStatementPasses)
- Write Tests (analyze-fixtures directory): One example with yoda and one without (again look at the existing ones for statements)
- Write a chapter in docs/05_Analyzers.md (its sorted alphabetically)
Check our Contribution Guide and create a pull request.
Thanks 🍰
ddmler commented
closed - merged in 230