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

CompareWithArray   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 18 3
A getRegister() 0 9 1
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