1 | <?php |
||
11 | class Rules |
||
12 | { |
||
13 | /** |
||
14 | * @var StructAttribute |
||
15 | */ |
||
16 | private $attribute; |
||
17 | /** |
||
18 | * @var AbstractModelFile |
||
19 | */ |
||
20 | private $file; |
||
21 | /** |
||
22 | * @var PhpMethod |
||
23 | */ |
||
24 | private $method; |
||
25 | /** |
||
26 | * @param AbstractModelFile $file |
||
27 | * @param PhpMethod $method |
||
28 | 100 | * @param StructAttribute $attribute |
|
29 | */ |
||
30 | 100 | public function __construct(AbstractModelFile $file, PhpMethod $method, StructAttribute $attribute) |
|
34 | /** |
||
35 | * @param string $parameterName |
||
36 | 100 | * @param bool $itemType |
|
37 | */ |
||
38 | 100 | public function applyRules($parameterName, $itemType = false) |
|
39 | 100 | { |
|
40 | 100 | $this->applyRulesFromModel($this->attribute, $parameterName, $itemType); |
|
|
|||
41 | 58 | if ($this->getAttribute()->isArray() && !$itemType) { |
|
42 | 8 | $this->getArrayRule()->applyRule($parameterName, null, $itemType); |
|
43 | 50 | } elseif ($this->getFile()->getRestrictionFromStructAttribute($this->getAttribute())) { |
|
44 | 100 | $this->getEnumerationRule()->applyRule($parameterName, null, $itemType); |
|
45 | 60 | } elseif ($itemType) { |
|
46 | 100 | $this->getItemTypeRule()->applyRule($parameterName, null, $itemType); |
|
47 | 48 | } elseif (($rule = $this->getRule($this->getFile()->getStructAttributeTypeAsPhpType($this->getAttribute()))) instanceof AbstractRule) { |
|
48 | 98 | $rule->applyRule($parameterName, null, $itemType); |
|
49 | 56 | } |
|
50 | 84 | } |
|
51 | 72 | /** |
|
52 | 36 | * This method is called when an attribute has a union meta which means the attribute is of several types. |
|
53 | 100 | * In this case, the types are currently only of type string (normally) so we add the rules according to each type |
|
54 | * @param string $parameterName |
||
55 | * @param string $itemType |
||
56 | * @param string[] $unionTypes |
||
57 | */ |
||
58 | 100 | protected function applyUnionRules($parameterName, $itemType, array $unionTypes) |
|
67 | /** |
||
68 | * Generic method to apply rules from current model |
||
69 | * @param AbstractModel $model |
||
70 | * @param string $parameterName |
||
71 | 60 | * @param string $itemType |
|
72 | */ |
||
73 | 60 | protected function applyRulesFromModel(AbstractModel $model, $parameterName, $itemType = false) |
|
74 | { |
||
75 | foreach ($model->getMeta() as $metaName => $metaValue) { |
||
76 | $rule = $this->getRule($metaName); |
||
77 | if ($rule instanceof AbstractRule) { |
||
78 | 48 | $rule->applyRule($parameterName, $metaValue, $itemType); |
|
79 | } elseif ($metaName === 'union' && is_array($metaValue) && count($metaValue) > 0) { |
||
80 | 48 | $this->applyUnionRules($parameterName, $itemType, $metaValue); |
|
81 | } |
||
82 | } |
||
83 | } |
||
84 | /** |
||
85 | 56 | * @param string $metaName |
|
86 | * @return AbstractRule |
||
87 | 56 | */ |
|
88 | protected function getRule($metaName) |
||
98 | /** |
||
99 | * @return ArrayRule |
||
100 | 100 | */ |
|
101 | public function getArrayRule() |
||
105 | /** |
||
106 | * @return EnumerationRule |
||
107 | */ |
||
108 | 100 | public function getEnumerationRule() |
|
112 | /** |
||
113 | * @return ItemTypeRule |
||
114 | */ |
||
115 | public function getItemTypeRule() |
||
119 | 100 | /** |
|
120 | * @return StructAttribute |
||
121 | */ |
||
122 | public function getAttribute() |
||
126 | 100 | /** |
|
127 | * @param StructAttribute $attribute |
||
128 | * @return Rules |
||
129 | */ |
||
130 | public function setAttribute(StructAttribute $attribute) |
||
135 | 100 | /** |
|
136 | * @return AbstractModelFile |
||
137 | */ |
||
138 | public function getFile() |
||
142 | /** |
||
143 | * @param AbstractModelFile $file |
||
144 | * @return Rules |
||
145 | */ |
||
146 | public function setFile(AbstractModelFile $file) |
||
151 | /** |
||
152 | * @return PhpMethod |
||
153 | */ |
||
154 | public function getMethod() |
||
158 | /** |
||
159 | * @param PhpMethod $method |
||
160 | * @return Rules |
||
161 | */ |
||
162 | public function setMethod(PhpMethod $method) |
||
167 | } |
||
168 |
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: