Completed
Push — master ( 28d1f7...8f0d0f )
by Enrico
05:45
created

AssignRefNew::pass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\Expression;
7
8
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
9
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
10
use PhpParser\Node\Expr;
11
use PHPSA\Context;
12
13
class AssignRefNew implements AnalyzerPassInterface
14
{
15
    use DefaultMetadataPassTrait {
16
        DefaultMetadataPassTrait::getMetadata as defaultMetadata;
17
    }
18
19
    const DESCRIPTION = 'Protection of usage & and new.';
20
21
    /**
22
     * @param Expr\AssignRef $expr
23
     * @param Context $context
24
     * @return bool
25
     */
26 2
    public function pass(Expr\AssignRef $expr, Context $context)
27
    {
28 2
        if ($expr->expr instanceof Expr\New_) {
29 1
            $context->notice(
30 1
                'assign_ref_new',
31 1
                'Do not use = & new, all objects in PHP are passed by reference',
32
                $expr
33 1
            );
34
35 1
            return true;
36
        }
37
38 1
        return false;
39
    }
40
41
    /**
42
     * @return array
43
     */
44 2
    public function getRegister()
45
    {
46
        return [
47
            Expr\AssignRef::class
48 2
        ];
49
    }
50
}
51