Completed
Pull Request — master (#335)
by Дмитрий
02:26
created

ExpressionBeforeCompile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getExpression() 0 4 1
A getContext() 0 4 1
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Compiler\Event;
7
8
use PHPSA\Context;
9
10
class ExpressionBeforeCompile extends \Webiny\Component\EventManager\Event
11
{
12
    const EVENT_NAME = 'expression.before-compile';
13
14
    /**
15
     * @var Context
16
     */
17
    private $context;
18
19
    /**
20
     * @var \PhpParser\Node\Expr
21
     */
22
    private $expression;
23
24
    public function __construct(\PhpParser\NodeAbstract $expression, Context $context)
25
    {
26
        parent::__construct();
27
28
        $this->context = $context;
29
        $this->expression = $expression;
0 ignored issues
show
Documentation Bug introduced by
$expression is of type object<PhpParser\NodeAbstract>, but the property $expression was declared to be of type object<PhpParser\Node\Expr>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
30
    }
31
32
    /**
33
     * @return \PhpParser\Node\Expr
34
     */
35
    public function getExpression()
36
    {
37
        return $this->expression;
38
    }
39
40
    /**
41
     * @return Context
42
     */
43
    public function getContext()
44
    {
45
        return $this->context;
46
    }
47
}
48