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

AssignRefNew   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 38
ccs 9
cts 10
cp 0.9
rs 10
c 1
b 0
f 0
wmc 3
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegister() 0 6 1
A pass() 0 14 2
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