Conditions | 6 |
Paths | 2 |
Total Lines | 18 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
16 | 12 | public function applyRule($parameterName, $value, $itemType = false) |
|
17 | { |
||
18 | 12 | if (is_array($value) && 0 < count($value)) { |
|
19 | 12 | $this->getMethod() |
|
20 | 12 | ->addChild('// validation(s) for constraint: choice'); |
|
21 | |||
22 | 12 | $attribute = $this->getAttribute(); |
|
23 | 12 | $struct = $attribute->getOwner(); |
|
24 | 12 | foreach ($value as $choiceName) { |
|
25 | 12 | if ($choiceName !== $attribute->getName() && $choiceAttribute = $struct->getAttribute($choiceName)) { |
|
26 | 12 | $this->getMethod() |
|
27 | 12 | ->addChild(sprintf('if (isset($this->%s)) {', $choiceAttribute->getCleanName())) |
|
28 | 12 | ->addChild($this->getMethod()->getIndentedString(sprintf('throw new \InvalidArgumentException(\'The property %s can\\\'t be set as the property %s is already set. Only one property must be set among these properties: %s.\');', $attribute->getName(), $choiceAttribute->getName(), implode(', ', $value)), 1)) |
|
29 | 12 | ->addChild(sprintf('}')); |
|
30 | 6 | } |
|
31 | 6 | } |
|
32 | 6 | } |
|
33 | 12 | return $this; |
|
34 | } |
||
36 |