|
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\Definition; |
|
11
|
|
|
|
|
12
|
|
|
use Railt\SDL\Frontend\Context\ContextInterface; |
|
13
|
|
|
use Railt\SDL\IR\Type\TypeNameInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class Definition |
|
17
|
|
|
*/ |
|
18
|
|
|
class Definition implements DefinitionInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var TypeNameInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $name; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var ContextInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $context; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
private $arguments = []; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Definition constructor. |
|
37
|
|
|
* @param ContextInterface $context |
|
38
|
|
|
* @param TypeNameInterface $name |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(ContextInterface $context, TypeNameInterface $name) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->context = $context; |
|
43
|
|
|
$this->name = $name->in($context->getName()); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return iterable|DefinitionArgumentInterface[] |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getArguments(): iterable |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->arguments; |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $name |
|
56
|
|
|
* @param TypeNameInterface $hint |
|
57
|
|
|
* @return DefinitionArgumentInterface |
|
58
|
|
|
*/ |
|
59
|
|
|
public function addArgument(string $name, TypeNameInterface $hint): DefinitionArgumentInterface |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->arguments[$name] = new Argument($name, $hint); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param string $name |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
public function hasArgument(string $name): bool |
|
69
|
|
|
{ |
|
70
|
|
|
return isset($this->arguments[$name]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $name |
|
75
|
|
|
* @return DefinitionArgumentInterface |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getArgument(string $name): DefinitionArgumentInterface |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->arguments[$name]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return TypeNameInterface |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getName(): TypeNameInterface |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->name; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return ContextInterface |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getContext(): ContextInterface |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->context; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return bool |
|
100
|
|
|
*/ |
|
101
|
|
|
public function isGeneric(): bool |
|
102
|
|
|
{ |
|
103
|
|
|
return \count($this->arguments) > 0; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..