| 1 | <?php |
||
| 10 | class CompareWithArray implements AnalyzerPassInterface |
||
| 11 | { |
||
| 12 | use DefaultMetadataPassTrait; |
||
| 13 | |||
| 14 | const DESCRIPTION = 'Checks for `{type array} > 1` and similar and suggests use of `count()`.'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param Expr\BinaryOp $expr |
||
| 18 | * @param Context $context |
||
| 19 | * @return bool |
||
| 20 | */ |
||
| 21 | 16 | public function pass(Expr\BinaryOp $expr, Context $context) |
|
| 22 | { |
||
| 23 | 16 | $compiler = $context->getExpressionCompiler(); |
|
| 24 | 16 | $left = $compiler->compile($expr->left); |
|
| 25 | 16 | $right = $compiler->compile($expr->right); |
|
| 26 | |||
| 27 | 16 | if ($left->isArray() || $right->isArray()) { |
|
| 28 | 1 | $context->notice( |
|
| 29 | 1 | 'compare_with_array', |
|
| 30 | 1 | "You are comparing an array. Did you want to use count()?", |
|
| 31 | $expr |
||
| 32 | 1 | ); |
|
| 33 | |||
| 34 | 1 | return true; |
|
| 35 | } |
||
| 36 | |||
| 37 | 15 | return false; |
|
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | 2 | public function getRegister() |
|
| 52 | } |
||
| 53 |