Completed
Pull Request — master (#198)
by Enrico
04:21
created

CompareWithArray::pass()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
nc 2
nop 2
dl 0
loc 18
ccs 11
cts 11
cp 1
crap 3
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Expression;
4
5
use PhpParser\Node\Expr;
6
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
7
use PHPSA\Context;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use PHPSA\CompiledExpression;
10
11
class CompareWithArray implements AnalyzerPassInterface
12
{
13
    /**
14
     * @param Expr $expr
15
     * @param Context $context
16
     * @return bool
17
     */
18 49
    public function pass(Expr $expr, Context $context)
19
    {
20 49
        $compiler = $context->getExpressionCompiler();
21 49
        $left = $compiler->compile($expr->left);
0 ignored issues
show
Bug introduced by
The property left does not seem to exist in PhpParser\Node\Expr.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
22 49
        $right = $compiler->compile($expr->right);
0 ignored issues
show
Bug introduced by
The property right does not seem to exist in PhpParser\Node\Expr.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
23
24 49
        if ($left->isArray() || $right->isArray()) {
25 1
            $context->notice(
26 1
                'compare_with_array',
27 1
                "You are comparing an array. Did you want to use count()?",
28
                $expr
29 1
            );
30
31 1
            return true;
32
        }
33
        
34 48
        return false;
35
    }
36
37
    /**
38
     * @return array
39
     */
40 1
    public function getRegister()
41
    {
42
        return [
43 1
            Expr\BinaryOp\Greater::class,
44 1
            Expr\BinaryOp\GreaterOrEqual::class,
45 1
            Expr\BinaryOp\Smaller::class,
46 1
            Expr\BinaryOp\SmallerOrEqual::class,
47 1
        ];
48
    }
49
}
50