Conflict   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isShiftReduce() 0 4 1
A isReduceReduce() 0 4 1
A symbol() 0 4 1
A next() 0 4 1
A setNext() 0 4 1
1
<?php
2
/**
3
 * This file is part of PHP-Yacc package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace PhpYacc\Lalr;
11
12
use PhpYacc\Grammar\Symbol;
13
14
/**
15
 * Class Conflict.
16
 */
17
abstract class Conflict
18
{
19
    /**
20
     * @var null|Conflict
21
     */
22
    protected $next;
23
24
    /**
25
     * @var Symbol
26
     */
27
    protected $symbol;
28
29
    /**
30
     * Conflict constructor.
31
     *
32
     * @param Symbol        $symbol
33
     * @param Conflict|null $next
34
     */
35
    protected function __construct(Symbol $symbol, self $next = null)
36
    {
37
        $this->next = $next;
0 ignored issues
show
Documentation Bug introduced by
It seems like $next can also be of type object<self>. However, the property $next is declared as type null|object<PhpYacc\Lalr\Conflict>. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
38
        $this->symbol = $symbol;
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function isShiftReduce(): bool
45
    {
46
        return false;
47
    }
48
49
    /**
50
     * @return bool
51
     */
52
    public function isReduceReduce(): bool
53
    {
54
        return false;
55
    }
56
57
    /**
58
     * @return Symbol
59
     */
60
    public function symbol(): Symbol
61
    {
62
        return $this->symbol;
63
    }
64
65
    /**
66
     * @return null|Conflict
67
     */
68
    public function next()
69
    {
70
        return $this->next;
71
    }
72
73
    /**
74
     * @param Conflict|null $next
75
     */
76
    public function setNext(self $next = null)
77
    {
78
        $this->next = $next;
0 ignored issues
show
Documentation Bug introduced by
It seems like $next can also be of type object<self>. However, the property $next is declared as type null|object<PhpYacc\Lalr\Conflict>. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
79
    }
80
}
81