Completed
Push — master ( 69939e...ded049 )
by Enrico
02:49
created

AssignRefNew::pass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 14
ccs 7
cts 8
cp 0.875
crap 2.0078
rs 9.4285
c 1
b 0
f 0
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 1
    public function pass(Expr\AssignRef $expr, Context $context)
27
    {
28 1
        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
        return false;
39
    }
40
41
    /**
42
     * @return array
43
     */
44 1
    public function getRegister()
45
    {
46
        return [
47
            Expr\AssignRef::class
48 1
        ];
49
    }
50
}
51