|
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\AST\Value\ValueInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class InputInvocationNode |
|
21
|
|
|
*/ |
|
22
|
|
|
class InputInvocationNode extends Rule implements ProvidesType, ValueInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @return TypeInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getType(): TypeInterface |
|
28
|
|
|
{ |
|
29
|
|
|
return Type::of(Type::INPUT_OBJECT); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
|
|
public function toString(): string |
|
36
|
|
|
{ |
|
37
|
|
|
$result = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string $name |
|
41
|
|
|
* @var ValueInterface $value |
|
42
|
|
|
*/ |
|
43
|
|
|
foreach ($this->getValues() as [$name, $value]) { |
|
44
|
|
|
$result[] = $name . ': ' . $value->toString(); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return \sprintf('{%s}', \implode(', ', $result)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return iterable|array[] |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getValues(): iterable |
|
54
|
|
|
{ |
|
55
|
|
|
/** @var RuleInterface $arguments */ |
|
56
|
|
|
$arguments = $this->first('InputInvocationArguments', 1); |
|
57
|
|
|
|
|
58
|
|
|
if ($arguments) { |
|
59
|
|
|
/** @var ArgumentInvocationNode $child */ |
|
60
|
|
|
foreach ($arguments as $child) { |
|
61
|
|
|
yield $child => [$child->getFullName(), $child->getValue()]; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return iterable|ValueInterface[] |
|
68
|
|
|
*/ |
|
69
|
|
|
public function toPrimitive(): iterable |
|
70
|
|
|
{ |
|
71
|
|
|
$result = []; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var RuleInterface $ast |
|
75
|
|
|
* @var string $name |
|
76
|
|
|
* @var ValueInterface $value |
|
77
|
|
|
*/ |
|
78
|
|
|
foreach ($this->getValues() as $ast => [$name, $value]) { |
|
79
|
|
|
$result[$name] = $value->toPrimitive(); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $result; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.