Conditions | 2 |
Paths | 2 |
Total Lines | 13 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 2 |
1 | <?php |
||
17 | public function applyRule($parameterName, $value, $itemType = false) |
||
18 | { |
||
19 | $attribute = $this->getAttribute(); |
||
20 | if (($model = $this->getFile()->getRestrictionFromStructAttribute($attribute)) instanceof Struct) { |
||
21 | $this |
||
22 | ->getMethod() |
||
23 | ->addChild('// validation for constraint: enumeration') |
||
24 | ->addChild(sprintf('if (!%s::%s($%s)) {', $model->getPackagedName(true), StructEnum::METHOD_VALUE_IS_VALID, $parameterName)) |
||
25 | ->addChild($this->getMethod()->getIndentedString(sprintf('throw new \InvalidArgumentException(sprintf(\'Value "%%s" is invalid, please use one of: %%s\', $%s, implode(\', \', %s::%s())), __LINE__);', $parameterName, $model->getPackagedName(true), StructEnum::METHOD_GET_VALID_VALUES), 1)) |
||
26 | ->addChild('}'); |
||
27 | } |
||
28 | return $this; |
||
29 | } |
||
30 | } |
||
31 |