Completed
Pull Request — master (#251)
by
unknown
11:10
created

ScalarBeforeCompile::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PHPSA\Compiler\Event;
4
5
use PHPSA\Context;
6
7
class ScalarBeforeCompile extends \Webiny\Component\EventManager\Event
8
{
9
    const EVENT_NAME = 'scalar.before-compile';
10
11
    /**
12
     * @var Context
13
     */
14
    private $context;
15
16
    /**
17
     * @var \PhpParser\Node\Scalar
18
     */
19
    private $scalar;
20
21 802
    public function __construct(\PhpParser\NodeAbstract $scalar, Context $context)
22
    {
23 802
        parent::__construct();
24
25 802
        $this->context = $context;
26 802
        $this->scalar = $scalar;
0 ignored issues
show
Documentation Bug introduced by
$scalar is of type object<PhpParser\NodeAbstract>, but the property $scalar was declared to be of type object<PhpParser\Node\Scalar>. 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...
27 802
    }
28
29
    /**
30
     * @return \PhpParser\Node\Scalar
31
     */
32 802
    public function getScalar()
33
    {
34 802
        return $this->scalar;
35
    }
36
37
    /**
38
     * @return Context
39
     */
40 491
    public function getContext()
41
    {
42 491
        return $this->context;
43
    }
44
}
45