Completed
Pull Request — master (#150)
by Дмитрий
03:17
created

ExpressionAfterCompile::getExpression()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
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 ExpressionAfterCompile extends \Webiny\Component\EventManager\Event
11
{
12
    const EVENT_NAME = 'expression.after-compile';
13
14
    /**
15
     * @var Context
16
     */
17
    protected $context;
18
19
    /**
20
     * @var \PhpParser\Node\Expr
21
     */
22
    protected $expression;
23
24
    /**
25
     * @var mixed
26
     */
27
    protected $result;
28
29
    public function __construct(\PhpParser\NodeAbstract $expression, Context $context, $result)
30
    {
31
        parent::__construct();
32
33
        $this->context = $context;
34
        $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...
35
        $this->result = $result;
36
    }
37
38
    /**
39
     * @return \PhpParser\Node\Expr
40
     */
41
    public function getExpression()
42
    {
43
        return $this->expression;
44
    }
45
46
    /**
47
     * @return Context
48
     */
49
    public function getContext()
50
    {
51
        return $this->context;
52
    }
53
54
    /**
55
     * @return mixed
56
     */
57
    public function getResult()
58
    {
59
        return $this->result;
60
    }
61
}
62