@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | $this->validateNotNull($key); |
24 | 24 | $this->validateNotObjectOrHasToString($key); |
25 | 25 | |
26 | - if (is_numeric($key) || is_string($key)) |
|
27 | - return $key; |
|
26 | + if (is_numeric($key) || is_string($key)) { |
|
27 | + return $key; |
|
28 | + } |
|
28 | 29 | |
29 | 30 | return (string) $key; |
30 | 31 | } |
@@ -34,8 +35,9 @@ discard block |
||
34 | 35 | * @throws InvalidTypeException |
35 | 36 | */ |
36 | 37 | private function validateNotNull($key) { |
37 | - if (is_null($key)) |
|
38 | - throw new InvalidTypeException('Can not use null for a key'); |
|
38 | + if (is_null($key)) { |
|
39 | + throw new InvalidTypeException('Can not use null for a key'); |
|
40 | + } |
|
39 | 41 | } |
40 | 42 | |
41 | 43 | /** |
@@ -43,7 +45,8 @@ discard block |
||
43 | 45 | * @throws InvalidTypeException |
44 | 46 | */ |
45 | 47 | private function validateNotObjectOrHasToString($key) { |
46 | - if (is_object($key) && !method_exists($key, '__toString')) |
|
47 | - throw new InvalidTypeException('Object keys must implement __toString'); |
|
48 | + if (is_object($key) && !method_exists($key, '__toString')) { |
|
49 | + throw new InvalidTypeException('Object keys must implement __toString'); |
|
50 | + } |
|
48 | 51 | } |
49 | 52 | } |
50 | 53 | \ No newline at end of file |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | protected $validators = []; |
16 | 16 | |
17 | 17 | public function __construct($name) { |
18 | - if (!$this->isValidName($name)) |
|
19 | - throw new InvalidFieldNameException(); |
|
18 | + if (!$this->isValidName($name)) { |
|
19 | + throw new InvalidFieldNameException(); |
|
20 | + } |
|
20 | 21 | $this->name = $name; |
21 | 22 | } |
22 | 23 | |
@@ -47,11 +48,13 @@ discard block |
||
47 | 48 | } |
48 | 49 | |
49 | 50 | public function validate($value): ValidationResult { |
50 | - if ($this->isRequiredOrNotEmpty($value)) |
|
51 | - $this->runValidators($value); |
|
51 | + if ($this->isRequiredOrNotEmpty($value)) { |
|
52 | + $this->runValidators($value); |
|
53 | + } |
|
52 | 54 | |
53 | - if ($this->isRequiredAndEmpty($value) && count($this->messages) === 0) |
|
54 | - $this->addMessage('Required'); |
|
55 | + if ($this->isRequiredAndEmpty($value) && count($this->messages) === 0) { |
|
56 | + $this->addMessage('Required'); |
|
57 | + } |
|
55 | 58 | |
56 | 59 | return $this->validationResult(); |
57 | 60 | } |
@@ -90,8 +93,9 @@ discard block |
||
90 | 93 | |
91 | 94 | protected function runValidators($value) { |
92 | 95 | foreach ($this->validators as $validator) { |
93 | - if (!$validator->validate($value)) |
|
94 | - $this->addMessage($validator->getDescription()); |
|
96 | + if (!$validator->validate($value)) { |
|
97 | + $this->addMessage($validator->getDescription()); |
|
98 | + } |
|
95 | 99 | } |
96 | 100 | } |
97 | 101 |