Test Failed
Push — master ( 3e22f3...90cc1b )
by Kirill
03:50
created

DirectiveArgumentNode::getArgumentValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
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\Compiler\Ast\Dependent;
11
12
use Railt\Parser\Ast\Rule;
13
use Railt\Reflection\Contracts\Invocation\TypeInvocation;
14
use Railt\Reflection\Invocation\Dependent\ArgumentInvocation;
15
use Railt\Reflection\Invocation\DirectiveInvocation;
16
use Railt\SDL\Compiler\Ast\Value\ValueInterface;
17
use Railt\SDL\Compiler\Ast\Value\ValueNode;
18
19
/**
20
 * Class DirectiveArgumentNode
21
 */
22
class DirectiveArgumentNode extends Rule
23
{
24
    /**
25
     * @param DirectiveInvocation $parent
26
     * @return TypeInvocation|ArgumentInvocation
27
     */
28
    public function getTypeInvocation(DirectiveInvocation $parent): TypeInvocation
29
    {
30
        $argument = new ArgumentInvocation($parent, $this->getArgumentName(), $this->getArgumentValue()->toPrimitive());
0 ignored issues
show
Bug introduced by
The call to ArgumentInvocation::__construct() misses a required argument $value.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$this->getArgumentName() is of type string, but the function expects a object<Railt\Reflection\Document>.

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...
31
        $argument->withOffset($this->getOffset());
32
33
        return $argument;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function getArgumentName(): string
40
    {
41
        return $this->first('T_NAME', 1)->getValue();
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on Railt\Parser\Ast\NodeInterface. Did you maybe mean getValues()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
42
    }
43
44
    /**
45
     * @return ValueInterface
46
     */
47
    public function getArgumentValue(): ValueInterface
48
    {
49
        /** @var ValueNode $value */
50
        $value = $this->first('Value', 1);
51
52
        return $value->getInnerValue();
53
    }
54
}
55