@@ -4,74 +4,74 @@ |
||
| 4 | 4 | |
| 5 | 5 | class RuleValidator |
| 6 | 6 | { |
| 7 | - private $dice; |
|
| 7 | + private $dice; |
|
| 8 | 8 | |
| 9 | - public function __construct(\Dice\Dice $dice) |
|
| 10 | - { |
|
| 11 | - $this->dice = $dice; |
|
| 12 | - } |
|
| 9 | + public function __construct(\Dice\Dice $dice) |
|
| 10 | + { |
|
| 11 | + $this->dice = $dice; |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function addRule($name, array $rule) |
|
| 15 | - { |
|
| 16 | - $this->checkValidKeys($rule); |
|
| 17 | - $this->checkBoolean($rule, 'inherit'); |
|
| 18 | - $this->checkBoolean($rule, 'shared'); |
|
| 19 | - $this->checkNumericArray($rule, 'constructParams'); |
|
| 20 | - $this->checkNumericArray($rule, 'shareInstances'); |
|
| 21 | - $this->checkNumericArray($rule, 'call'); |
|
| 22 | - $this->checkAssocArray($rule, 'call'); |
|
| 14 | + public function addRule($name, array $rule) |
|
| 15 | + { |
|
| 16 | + $this->checkValidKeys($rule); |
|
| 17 | + $this->checkBoolean($rule, 'inherit'); |
|
| 18 | + $this->checkBoolean($rule, 'shared'); |
|
| 19 | + $this->checkNumericArray($rule, 'constructParams'); |
|
| 20 | + $this->checkNumericArray($rule, 'shareInstances'); |
|
| 21 | + $this->checkNumericArray($rule, 'call'); |
|
| 22 | + $this->checkAssocArray($rule, 'call'); |
|
| 23 | 23 | |
| 24 | - $this->dice->addRule($name, $rule); |
|
| 25 | - } |
|
| 24 | + $this->dice->addRule($name, $rule); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function create($name, array $args = [], array $share = []) |
|
| 28 | - { |
|
| 29 | - return $this->dice->create($name, $args, $share); |
|
| 30 | - } |
|
| 27 | + public function create($name, array $args = [], array $share = []) |
|
| 28 | + { |
|
| 29 | + return $this->dice->create($name, $args, $share); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function checkAssocArray($rule, $key) |
|
| 33 | - { |
|
| 34 | - if (!isset($rule[$key])) { |
|
| 35 | - return; |
|
| 36 | - } |
|
| 32 | + public function checkAssocArray($rule, $key) |
|
| 33 | + { |
|
| 34 | + if (!isset($rule[$key])) { |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - if (count(array_filter(array_keys($rule[$key]), 'is_string')) === 0) { |
|
| 39 | - throw new \InvalidArgumentException('Rule option ' . $key . ' must be a an associative array'); |
|
| 40 | - } |
|
| 38 | + if (count(array_filter(array_keys($rule[$key]), 'is_string')) === 0) { |
|
| 39 | + throw new \InvalidArgumentException('Rule option ' . $key . ' must be a an associative array'); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function checkBoolean($rule, $key) |
|
| 45 | - { |
|
| 46 | - if (!isset($rule[$key])) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 44 | + public function checkBoolean($rule, $key) |
|
| 45 | + { |
|
| 46 | + if (!isset($rule[$key])) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - if (!is_bool($rule[$key])) { |
|
| 51 | - throw new \InvalidArgumentException('Rule option ' . $key . ' must be true or false'); |
|
| 52 | - } |
|
| 53 | - } |
|
| 50 | + if (!is_bool($rule[$key])) { |
|
| 51 | + throw new \InvalidArgumentException('Rule option ' . $key . ' must be true or false'); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function checkNumericArray($rule, $key) |
|
| 56 | - { |
|
| 57 | - if (!isset($rule[$key])) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 55 | + public function checkNumericArray($rule, $key) |
|
| 56 | + { |
|
| 57 | + if (!isset($rule[$key])) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - if (count(array_filter(array_keys($rule[$key]), 'is_string')) > 0) { |
|
| 62 | - throw new \InvalidArgumentException('Rule option ' . $key |
|
| 63 | - . ' must be a sequential array, not an associative array'); |
|
| 64 | - } |
|
| 65 | - } |
|
| 61 | + if (count(array_filter(array_keys($rule[$key]), 'is_string')) > 0) { |
|
| 62 | + throw new \InvalidArgumentException('Rule option ' . $key |
|
| 63 | + . ' must be a sequential array, not an associative array'); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - private function checkValidKeys($rule) |
|
| 68 | - { |
|
| 69 | - $validKeys = ['call', 'shared', 'substitutions', 'instanceOf', 'inherit', 'shareInstances', 'constructParams']; |
|
| 67 | + private function checkValidKeys($rule) |
|
| 68 | + { |
|
| 69 | + $validKeys = ['call', 'shared', 'substitutions', 'instanceOf', 'inherit', 'shareInstances', 'constructParams']; |
|
| 70 | 70 | |
| 71 | - foreach ($rule as $name => $value) { |
|
| 72 | - if (!in_array($name, $validKeys)) { |
|
| 73 | - throw new \InvalidArgumentException('Invalid rule option: ' . $name); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 71 | + foreach ($rule as $name => $value) { |
|
| 72 | + if (!in_array($name, $validKeys)) { |
|
| 73 | + throw new \InvalidArgumentException('Invalid rule option: ' . $name); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | if (count(array_filter(array_keys($rule[$key]), 'is_string')) === 0) { |
| 39 | - throw new \InvalidArgumentException('Rule option ' . $key . ' must be a an associative array'); |
|
| 39 | + throw new \InvalidArgumentException('Rule option '.$key.' must be a an associative array'); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | if (!is_bool($rule[$key])) { |
| 51 | - throw new \InvalidArgumentException('Rule option ' . $key . ' must be true or false'); |
|
| 51 | + throw new \InvalidArgumentException('Rule option '.$key.' must be true or false'); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | if (count(array_filter(array_keys($rule[$key]), 'is_string')) > 0) { |
| 62 | - throw new \InvalidArgumentException('Rule option ' . $key |
|
| 62 | + throw new \InvalidArgumentException('Rule option '.$key |
|
| 63 | 63 | . ' must be a sequential array, not an associative array'); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | foreach ($rule as $name => $value) { |
| 72 | 72 | if (!in_array($name, $validKeys)) { |
| 73 | - throw new \InvalidArgumentException('Invalid rule option: ' . $name); |
|
| 73 | + throw new \InvalidArgumentException('Invalid rule option: '.$name); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |