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

InputInvocationNode::toPrimitive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
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\Rule;
13
use Railt\Parser\Ast\RuleInterface;
14
use Railt\Reflection\Contracts\TypeInterface;
15
use Railt\Reflection\Type;
16
use Railt\SDL\Frontend\AST\ProvidesType;
17
use Railt\SDL\Frontend\IR\Value\InputValue;
18
use Railt\SDL\Frontend\IR\Value\StringValue;
19
use Railt\SDL\Frontend\IR\Value\ValueInterface;
20
21
/**
22
 * Class InputInvocationNode
23
 */
24
class InputInvocationNode extends Rule implements ProvidesType, AstValueInterface
25
{
26
    /**
27
     * @return TypeInterface
28
     */
29
    public function getType(): TypeInterface
30
    {
31
        return Type::of(Type::INPUT_OBJECT);
32
    }
33
34
    /**
35
     * @return ValueInterface
36
     */
37
    public function unpack(): ValueInterface
38
    {
39
        return new InputValue($this->getInnerValues(), $this->getOffset());
0 ignored issues
show
Documentation introduced by
$this->getInnerValues() is of type object<Generator>, but the function expects a object<Railt\SDL\Frontend\IR\Value\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
    }
41
42
    /**
43
     * @return iterable|ValueInterface[]
44
     */
45
    private function getInnerValues(): iterable
46
    {
47
        /** @var RuleInterface $arguments */
48
        $arguments = $this->first('InputInvocationArguments', 1);
49
50
        if ($arguments) {
51
            /** @var ArgumentInvocationNode $child */
52
            foreach ($arguments as $child) {
53
                yield $child->getKey() => $child->getValue();
54
            }
55
        }
56
    }
57
}
58