Test Failed
Push — master ( ecd78b...d05c81 )
by Kirill
02:43
created

ValueNode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A unpack() 0 4 1
A getInnerValue() 0 4 1
1
<?php
2
/**
3
 * This file is part of Railt 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 Railt\SDL\Frontend\AST\Invocation;
11
12
use Railt\Parser\Ast\NodeInterface;
13
use Railt\Parser\Ast\Rule;
14
use Railt\SDL\Frontend\IR\Value\ValueInterface;
15
16
/**
17
 * Class ValueNode
18
 */
19
class ValueNode extends Rule implements AstValueInterface
20
{
21
    /**
22
     * @return ValueInterface
23
     */
24
    public function unpack(): ValueInterface
25
    {
26
        return $this->getInnerValue()->unpack();
0 ignored issues
show
Bug introduced by
The method unpack does only exist in Railt\SDL\Frontend\AST\I...ation\AstValueInterface, but not in Railt\Parser\Ast\NodeInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
27
    }
28
29
    /**
30
     * @return AstValueInterface|NodeInterface
31
     */
32
    private function getInnerValue(): AstValueInterface
33
    {
34
        return $this->getChild(0);
35
    }
36
}
37