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

ScalarBeforeCompile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 9
cts 9
cp 1
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 getScalar() 0 4 1
A getContext() 0 4 1
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