Test Failed
Push — master ( a0eed4...bb00ac )
by Kirill
149:40
created

ArgumentValueNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 4 1
A getValue() 0 11 3
A toValue() 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\Io\Readable;
13
use Railt\Parser\Ast\RuleInterface;
14
use Railt\SDL\Frontend\AST\Definition\Provider\DependentNameProvider;
15
use Railt\SDL\IR\Value;
16
use Railt\SDL\IR\ValueInterface;
17
18
/**
19
 * Class ArgumentValue
20
 */
21
class ArgumentValueNode extends AbstractValueNode
22
{
23
    use DependentNameProvider;
24
25
    /**
26
     * @return \Generator|mixed
27
     */
28
    protected function parse()
29
    {
30
        yield $this->getFullName() => $this->getValue()->toPrimitive();
0 ignored issues
show
Bug introduced by
The method toPrimitive does only exist in Railt\SDL\Frontend\AST\I...ation\AstValueInterface, but not in Railt\Parser\Ast\RuleInterface.

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...
31
    }
32
33
    /**
34
     * @return null|RuleInterface|AstValueInterface
35
     */
36
    public function getValue()
37
    {
38
        /** @var RuleInterface|AstValueInterface $child */
39
        foreach ($this->getChildren() as $child) {
40
            if (\in_array($child->getName(), static::VALUE_NODE_NAMES, true)) {
41
                return $child;
42
            }
43
        }
44
45
        return null;
46
    }
47
48
    /**
49
     * @param Readable $file
50
     * @return ValueInterface
51
     */
52
    public function toValue(Readable $file): ValueInterface
53
    {
54
        return $this->getValue()->toValue($file);
0 ignored issues
show
Bug introduced by
The method toValue does only exist in Railt\SDL\Frontend\AST\I...ation\AstValueInterface, but not in Railt\Parser\Ast\RuleInterface.

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...
55
    }
56
}
57