@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function format($value, string $format): bool |
80 | 80 | { |
81 | - if (!$this->isApplicableValue($value)) { |
|
81 | + if (!$this->isApplicableValue($value)){ |
|
82 | 82 | return false; |
83 | 83 | } |
84 | 84 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function timezone($value): bool |
106 | 106 | { |
107 | - if (!is_scalar($value)) { |
|
107 | + if (!is_scalar($value)){ |
|
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | */ |
137 | 137 | private function now(): ?DateTimeInterface |
138 | 138 | { |
139 | - try { |
|
139 | + try{ |
|
140 | 140 | return $this->date($this->now ?: 'now'); |
141 | - } catch (Throwable $e) { |
|
141 | + }catch (Throwable $e){ |
|
142 | 142 | //here's the fail; |
143 | 143 | } |
144 | 144 | |
@@ -150,25 +150,25 @@ discard block |
||
150 | 150 | */ |
151 | 151 | private function date($value): ?DateTimeInterface |
152 | 152 | { |
153 | - if (is_callable($value)) { |
|
153 | + if (is_callable($value)){ |
|
154 | 154 | $value = $value(); |
155 | 155 | } |
156 | 156 | |
157 | - if ($value instanceof DateTimeInterface) { |
|
157 | + if ($value instanceof DateTimeInterface){ |
|
158 | 158 | return $value; |
159 | 159 | } |
160 | 160 | |
161 | - if (!$this->isApplicableValue($value)) { |
|
161 | + if (!$this->isApplicableValue($value)){ |
|
162 | 162 | return null; |
163 | 163 | } |
164 | 164 | |
165 | - try { |
|
166 | - if (!$value) { |
|
165 | + try{ |
|
166 | + if (!$value){ |
|
167 | 167 | $value = '0'; |
168 | 168 | } |
169 | 169 | |
170 | 170 | return new DateTimeImmutable(is_numeric($value) ? sprintf('@%d', $value) : trim($value)); |
171 | - } catch (Throwable $e) { |
|
171 | + }catch (Throwable $e){ |
|
172 | 172 | //here's the fail; |
173 | 173 | } |
174 | 174 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | private function fromField(string $field): ?DateTimeInterface |
187 | 187 | { |
188 | 188 | $before = $this->getValidator()->getValue($field); |
189 | - if ($before !== null) { |
|
189 | + if ($before !== null){ |
|
190 | 190 | return $this->date($before); |
191 | 191 | } |
192 | 192 |
@@ -78,7 +78,8 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function format($value, string $format): bool |
80 | 80 | { |
81 | - if (!$this->isApplicableValue($value)) { |
|
81 | + if (!$this->isApplicableValue($value)) |
|
82 | + { |
|
82 | 83 | return false; |
83 | 84 | } |
84 | 85 | |
@@ -104,7 +105,8 @@ discard block |
||
104 | 105 | */ |
105 | 106 | public function timezone($value): bool |
106 | 107 | { |
107 | - if (!is_scalar($value)) { |
|
108 | + if (!is_scalar($value)) |
|
109 | + { |
|
108 | 110 | return false; |
109 | 111 | } |
110 | 112 | |
@@ -136,9 +138,12 @@ discard block |
||
136 | 138 | */ |
137 | 139 | private function now(): ?DateTimeInterface |
138 | 140 | { |
139 | - try { |
|
141 | + try |
|
142 | + { |
|
140 | 143 | return $this->date($this->now ?: 'now'); |
141 | - } catch (Throwable $e) { |
|
144 | + } |
|
145 | + catch (Throwable $e) |
|
146 | + { |
|
142 | 147 | //here's the fail; |
143 | 148 | } |
144 | 149 | |
@@ -150,25 +155,32 @@ discard block |
||
150 | 155 | */ |
151 | 156 | private function date($value): ?DateTimeInterface |
152 | 157 | { |
153 | - if (is_callable($value)) { |
|
158 | + if (is_callable($value)) |
|
159 | + { |
|
154 | 160 | $value = $value(); |
155 | 161 | } |
156 | 162 | |
157 | - if ($value instanceof DateTimeInterface) { |
|
163 | + if ($value instanceof DateTimeInterface) |
|
164 | + { |
|
158 | 165 | return $value; |
159 | 166 | } |
160 | 167 | |
161 | - if (!$this->isApplicableValue($value)) { |
|
168 | + if (!$this->isApplicableValue($value)) |
|
169 | + { |
|
162 | 170 | return null; |
163 | 171 | } |
164 | 172 | |
165 | - try { |
|
166 | - if (!$value) { |
|
173 | + try |
|
174 | + { |
|
175 | + if (!$value) |
|
176 | + { |
|
167 | 177 | $value = '0'; |
168 | 178 | } |
169 | 179 | |
170 | 180 | return new DateTimeImmutable(is_numeric($value) ? sprintf('@%d', $value) : trim($value)); |
171 | - } catch (Throwable $e) { |
|
181 | + } |
|
182 | + catch (Throwable $e) |
|
183 | + { |
|
172 | 184 | //here's the fail; |
173 | 185 | } |
174 | 186 | |
@@ -186,7 +198,8 @@ discard block |
||
186 | 198 | private function fromField(string $field): ?DateTimeInterface |
187 | 199 | { |
188 | 200 | $before = $this->getValidator()->getValue($field); |
189 | - if ($before !== null) { |
|
201 | + if ($before !== null) |
|
202 | + { |
|
190 | 203 | return $this->date($before); |
191 | 204 | } |
192 | 205 |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | |
30 | 30 | public function of($value, $checker): bool |
31 | 31 | { |
32 | - if (!is_array($value) || empty($value)) { |
|
32 | + if (!is_array($value) || empty($value)){ |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | |
36 | - foreach ($value as $item) { |
|
37 | - if (!$this->validation->validate(compact('item'), ['item' => [$checker]])->isValid()) { |
|
36 | + foreach ($value as $item){ |
|
37 | + if (!$this->validation->validate(compact('item'), ['item' => [$checker]])->isValid()){ |
|
38 | 38 | return false; |
39 | 39 | } |
40 | 40 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | public function count($value, int $length): bool |
46 | 46 | { |
47 | - if (!is_array($value) && !$value instanceof Countable) { |
|
47 | + if (!is_array($value) && !$value instanceof Countable){ |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | public function shorter($value, int $length): bool |
55 | 55 | { |
56 | - if (!is_array($value) && !$value instanceof Countable) { |
|
56 | + if (!is_array($value) && !$value instanceof Countable){ |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public function longer($value, int $length): bool |
64 | 64 | { |
65 | - if (!is_array($value) && !$value instanceof Countable) { |
|
65 | + if (!is_array($value) && !$value instanceof Countable){ |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | public function range($value, int $min, int $max): bool |
73 | 73 | { |
74 | - if (!is_array($value) && !$value instanceof Countable) { |
|
74 | + if (!is_array($value) && !$value instanceof Countable){ |
|
75 | 75 | return false; |
76 | 76 | } |
77 | 77 |
@@ -29,12 +29,15 @@ discard block |
||
29 | 29 | |
30 | 30 | public function of($value, $checker): bool |
31 | 31 | { |
32 | - if (!is_array($value) || empty($value)) { |
|
32 | + if (!is_array($value) || empty($value)) |
|
33 | + { |
|
33 | 34 | return false; |
34 | 35 | } |
35 | 36 | |
36 | - foreach ($value as $item) { |
|
37 | - if (!$this->validation->validate(compact('item'), ['item' => [$checker]])->isValid()) { |
|
37 | + foreach ($value as $item) |
|
38 | + { |
|
39 | + if (!$this->validation->validate(compact('item'), ['item' => [$checker]])->isValid()) |
|
40 | + { |
|
38 | 41 | return false; |
39 | 42 | } |
40 | 43 | } |
@@ -44,7 +47,8 @@ discard block |
||
44 | 47 | |
45 | 48 | public function count($value, int $length): bool |
46 | 49 | { |
47 | - if (!is_array($value) && !$value instanceof Countable) { |
|
50 | + if (!is_array($value) && !$value instanceof Countable) |
|
51 | + { |
|
48 | 52 | return false; |
49 | 53 | } |
50 | 54 | |
@@ -53,7 +57,8 @@ discard block |
||
53 | 57 | |
54 | 58 | public function shorter($value, int $length): bool |
55 | 59 | { |
56 | - if (!is_array($value) && !$value instanceof Countable) { |
|
60 | + if (!is_array($value) && !$value instanceof Countable) |
|
61 | + { |
|
57 | 62 | return false; |
58 | 63 | } |
59 | 64 | |
@@ -62,7 +67,8 @@ discard block |
||
62 | 67 | |
63 | 68 | public function longer($value, int $length): bool |
64 | 69 | { |
65 | - if (!is_array($value) && !$value instanceof Countable) { |
|
70 | + if (!is_array($value) && !$value instanceof Countable) |
|
71 | + { |
|
66 | 72 | return false; |
67 | 73 | } |
68 | 74 | |
@@ -71,7 +77,8 @@ discard block |
||
71 | 77 | |
72 | 78 | public function range($value, int $min, int $max): bool |
73 | 79 | { |
74 | - if (!is_array($value) && !$value instanceof Countable) { |
|
80 | + if (!is_array($value) && !$value instanceof Countable) |
|
81 | + { |
|
75 | 82 | return false; |
76 | 83 | } |
77 | 84 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | bool $useMicroSeconds = false |
21 | 21 | ): bool { |
22 | 22 | $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds); |
23 | - if (is_bool($compare)) { |
|
23 | + if (is_bool($compare)){ |
|
24 | 24 | return $compare; |
25 | 25 | } |
26 | 26 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | bool $useMicroSeconds = false |
38 | 38 | ): bool { |
39 | 39 | $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds); |
40 | - if (is_bool($compare)) { |
|
40 | + if (is_bool($compare)){ |
|
41 | 41 | return $compare; |
42 | 42 | } |
43 | 43 | |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | */ |
50 | 50 | private function date($value): ?DateTimeImmutable |
51 | 51 | { |
52 | - if ($value instanceof DateTimeImmutable) { |
|
52 | + if ($value instanceof DateTimeImmutable){ |
|
53 | 53 | return $value; |
54 | 54 | } |
55 | 55 | |
56 | - if ($value instanceof DateTime) { |
|
56 | + if ($value instanceof DateTime){ |
|
57 | 57 | return DateTimeImmutable::createFromMutable($value); |
58 | 58 | } |
59 | 59 | |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | */ |
66 | 66 | private function compare(?DateTimeImmutable $date, ?DateTimeImmutable $threshold, bool $useMicroseconds) |
67 | 67 | { |
68 | - if ($date === null) { |
|
68 | + if ($date === null){ |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if ($threshold === null) { |
|
72 | + if ($threshold === null){ |
|
73 | 73 | return true; |
74 | 74 | } |
75 | 75 | |
76 | - if (!$useMicroseconds) { |
|
76 | + if (!$useMicroseconds){ |
|
77 | 77 | $date = $this->dropMicroSeconds($date); |
78 | 78 | $threshold = $this->dropMicroSeconds($threshold); |
79 | 79 | } |
@@ -20,7 +20,8 @@ discard block |
||
20 | 20 | bool $useMicroSeconds = false |
21 | 21 | ): bool { |
22 | 22 | $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds); |
23 | - if (is_bool($compare)) { |
|
23 | + if (is_bool($compare)) |
|
24 | + { |
|
24 | 25 | return $compare; |
25 | 26 | } |
26 | 27 | |
@@ -37,7 +38,8 @@ discard block |
||
37 | 38 | bool $useMicroSeconds = false |
38 | 39 | ): bool { |
39 | 40 | $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds); |
40 | - if (is_bool($compare)) { |
|
41 | + if (is_bool($compare)) |
|
42 | + { |
|
41 | 43 | return $compare; |
42 | 44 | } |
43 | 45 | |
@@ -49,11 +51,13 @@ discard block |
||
49 | 51 | */ |
50 | 52 | private function date($value): ?DateTimeImmutable |
51 | 53 | { |
52 | - if ($value instanceof DateTimeImmutable) { |
|
54 | + if ($value instanceof DateTimeImmutable) |
|
55 | + { |
|
53 | 56 | return $value; |
54 | 57 | } |
55 | 58 | |
56 | - if ($value instanceof DateTime) { |
|
59 | + if ($value instanceof DateTime) |
|
60 | + { |
|
57 | 61 | return DateTimeImmutable::createFromMutable($value); |
58 | 62 | } |
59 | 63 | |
@@ -65,15 +69,18 @@ discard block |
||
65 | 69 | */ |
66 | 70 | private function compare(?DateTimeImmutable $date, ?DateTimeImmutable $threshold, bool $useMicroseconds) |
67 | 71 | { |
68 | - if ($date === null) { |
|
72 | + if ($date === null) |
|
73 | + { |
|
69 | 74 | return false; |
70 | 75 | } |
71 | 76 | |
72 | - if ($threshold === null) { |
|
77 | + if ($threshold === null) |
|
78 | + { |
|
73 | 79 | return true; |
74 | 80 | } |
75 | 81 | |
76 | - if (!$useMicroseconds) { |
|
82 | + if (!$useMicroseconds) |
|
83 | + { |
|
77 | 84 | $date = $this->dropMicroSeconds($date); |
78 | 85 | $threshold = $this->dropMicroSeconds($threshold); |
79 | 86 | } |
@@ -43,11 +43,11 @@ |
||
43 | 43 | */ |
44 | 44 | public function getConditions(): Generator |
45 | 45 | { |
46 | - if (empty($this->conditions)) { |
|
46 | + if (empty($this->conditions)){ |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - foreach ($this->conditions as $condition) { |
|
50 | + foreach ($this->conditions as $condition){ |
|
51 | 51 | yield $condition->withOptions($this->conditions->offsetGet($condition)); |
52 | 52 | } |
53 | 53 | } |
@@ -43,11 +43,13 @@ |
||
43 | 43 | */ |
44 | 44 | public function getConditions(): Generator |
45 | 45 | { |
46 | - if (empty($this->conditions)) { |
|
46 | + if (empty($this->conditions)) |
|
47 | + { |
|
47 | 48 | return; |
48 | 49 | } |
49 | 50 | |
50 | - foreach ($this->conditions as $condition) { |
|
51 | + foreach ($this->conditions as $condition) |
|
52 | + { |
|
51 | 53 | yield $condition->withOptions($this->conditions->offsetGet($condition)); |
52 | 54 | } |
53 | 55 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function __construct(array $config = []) |
35 | 35 | { |
36 | 36 | parent::__construct($config); |
37 | - if (!empty($this->config['aliases'])) { |
|
37 | + if (!empty($this->config['aliases'])){ |
|
38 | 38 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
39 | 39 | } |
40 | 40 | } |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getChecker(string $name): Autowire |
52 | 52 | { |
53 | - if (!$this->hasChecker($name)) { |
|
53 | + if (!$this->hasChecker($name)){ |
|
54 | 54 | throw new ValidationException("Undefined checker `{$name}``."); |
55 | 55 | } |
56 | 56 | |
57 | 57 | $instance = $this->wire('checkers', $name); |
58 | - if ($instance !== null) { |
|
58 | + if ($instance !== null){ |
|
59 | 59 | return $instance; |
60 | 60 | } |
61 | 61 | |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | |
70 | 70 | public function getCondition(string $name): Autowire |
71 | 71 | { |
72 | - if (!$this->hasCondition($name)) { |
|
72 | + if (!$this->hasCondition($name)){ |
|
73 | 73 | throw new ValidationException("Undefined condition `{$name}`."); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $instance = $this->wire('conditions', $name); |
77 | - if ($instance !== null) { |
|
77 | + if ($instance !== null){ |
|
78 | 78 | return $instance; |
79 | 79 | } |
80 | 80 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function mapFunction($function) |
92 | 92 | { |
93 | - if (is_string($function)) { |
|
93 | + if (is_string($function)){ |
|
94 | 94 | $function = $this->resolveAlias($function); |
95 | - if (strpos($function, ':') !== false) { |
|
95 | + if (strpos($function, ':') !== false){ |
|
96 | 96 | $function = explode(':', $function); |
97 | 97 | } |
98 | 98 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | |
103 | 103 | private function wire(string $section, string $name): ?Autowire |
104 | 104 | { |
105 | - if (is_string($this->config[$section][$name])) { |
|
105 | + if (is_string($this->config[$section][$name])){ |
|
106 | 106 | return new Autowire($this->config[$section][$name]); |
107 | 107 | } |
108 | 108 | |
109 | - if (isset($this->config[$section][$name]['class'])) { |
|
109 | + if (isset($this->config[$section][$name]['class'])){ |
|
110 | 110 | return new Autowire( |
111 | 111 | $this->config[$section][$name]['class'], |
112 | 112 | $this->config[$section][$name]['options'] ?? [] |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | public function __construct(array $config = []) |
35 | 35 | { |
36 | 36 | parent::__construct($config); |
37 | - if (!empty($this->config['aliases'])) { |
|
37 | + if (!empty($this->config['aliases'])) |
|
38 | + { |
|
38 | 39 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
39 | 40 | } |
40 | 41 | } |
@@ -50,12 +51,14 @@ discard block |
||
50 | 51 | */ |
51 | 52 | public function getChecker(string $name): Autowire |
52 | 53 | { |
53 | - if (!$this->hasChecker($name)) { |
|
54 | + if (!$this->hasChecker($name)) |
|
55 | + { |
|
54 | 56 | throw new ValidationException("Undefined checker `{$name}``."); |
55 | 57 | } |
56 | 58 | |
57 | 59 | $instance = $this->wire('checkers', $name); |
58 | - if ($instance !== null) { |
|
60 | + if ($instance !== null) |
|
61 | + { |
|
59 | 62 | return $instance; |
60 | 63 | } |
61 | 64 | |
@@ -69,12 +72,14 @@ discard block |
||
69 | 72 | |
70 | 73 | public function getCondition(string $name): Autowire |
71 | 74 | { |
72 | - if (!$this->hasCondition($name)) { |
|
75 | + if (!$this->hasCondition($name)) |
|
76 | + { |
|
73 | 77 | throw new ValidationException("Undefined condition `{$name}`."); |
74 | 78 | } |
75 | 79 | |
76 | 80 | $instance = $this->wire('conditions', $name); |
77 | - if ($instance !== null) { |
|
81 | + if ($instance !== null) |
|
82 | + { |
|
78 | 83 | return $instance; |
79 | 84 | } |
80 | 85 | |
@@ -90,9 +95,11 @@ discard block |
||
90 | 95 | */ |
91 | 96 | public function mapFunction($function) |
92 | 97 | { |
93 | - if (is_string($function)) { |
|
98 | + if (is_string($function)) |
|
99 | + { |
|
94 | 100 | $function = $this->resolveAlias($function); |
95 | - if (strpos($function, ':') !== false) { |
|
101 | + if (strpos($function, ':') !== false) |
|
102 | + { |
|
96 | 103 | $function = explode(':', $function); |
97 | 104 | } |
98 | 105 | } |
@@ -102,11 +109,13 @@ discard block |
||
102 | 109 | |
103 | 110 | private function wire(string $section, string $name): ?Autowire |
104 | 111 | { |
105 | - if (is_string($this->config[$section][$name])) { |
|
112 | + if (is_string($this->config[$section][$name])) |
|
113 | + { |
|
106 | 114 | return new Autowire($this->config[$section][$name]); |
107 | 115 | } |
108 | 116 | |
109 | - if (isset($this->config[$section][$name]['class'])) { |
|
117 | + if (isset($this->config[$section][$name]['class'])) |
|
118 | + { |
|
110 | 119 | return new Autowire( |
111 | 120 | $this->config[$section][$name]['class'], |
112 | 121 | $this->config[$section][$name]['options'] ?? [] |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | |
59 | 59 | private function validateBoundaries(Boundary $from, Boundary $to): void |
60 | 60 | { |
61 | - if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) { |
|
61 | + if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)){ |
|
62 | 62 | throw new ValueException('Range boundaries should be applicable via passed type.'); |
63 | 63 | } |
64 | 64 | |
65 | - if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) { |
|
65 | + if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)){ |
|
66 | 66 | throw new ValueException('Range boundaries should be different.'); |
67 | 67 | } |
68 | 68 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | private function acceptsFrom($value): bool |
87 | 87 | { |
88 | - if ($this->from->empty) { |
|
88 | + if ($this->from->empty){ |
|
89 | 89 | return true; |
90 | 90 | } |
91 | 91 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | private function acceptsTo($value): bool |
101 | 101 | { |
102 | - if ($this->to->empty) { |
|
102 | + if ($this->to->empty){ |
|
103 | 103 | return true; |
104 | 104 | } |
105 | 105 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | private function setBoundaries(Boundary $from, Boundary $to): void |
112 | 112 | { |
113 | 113 | //Swap if from < to and both not empty |
114 | - if (!$from->empty && !$to->empty && $from->value > $to->value) { |
|
114 | + if (!$from->empty && !$to->empty && $from->value > $to->value){ |
|
115 | 115 | [$from, $to] = [$to, $from]; |
116 | 116 | } |
117 | 117 |
@@ -58,11 +58,13 @@ discard block |
||
58 | 58 | |
59 | 59 | private function validateBoundaries(Boundary $from, Boundary $to): void |
60 | 60 | { |
61 | - if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) { |
|
61 | + if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) |
|
62 | + { |
|
62 | 63 | throw new ValueException('Range boundaries should be applicable via passed type.'); |
63 | 64 | } |
64 | 65 | |
65 | - if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) { |
|
66 | + if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) |
|
67 | + { |
|
66 | 68 | throw new ValueException('Range boundaries should be different.'); |
67 | 69 | } |
68 | 70 | } |
@@ -85,7 +87,8 @@ discard block |
||
85 | 87 | */ |
86 | 88 | private function acceptsFrom($value): bool |
87 | 89 | { |
88 | - if ($this->from->empty) { |
|
90 | + if ($this->from->empty) |
|
91 | + { |
|
89 | 92 | return true; |
90 | 93 | } |
91 | 94 | |
@@ -99,7 +102,8 @@ discard block |
||
99 | 102 | */ |
100 | 103 | private function acceptsTo($value): bool |
101 | 104 | { |
102 | - if ($this->to->empty) { |
|
105 | + if ($this->to->empty) |
|
106 | + { |
|
103 | 107 | return true; |
104 | 108 | } |
105 | 109 | |
@@ -111,7 +115,8 @@ discard block |
||
111 | 115 | private function setBoundaries(Boundary $from, Boundary $to): void |
112 | 116 | { |
113 | 117 | //Swap if from < to and both not empty |
114 | - if (!$from->empty && !$to->empty && $from->value > $to->value) { |
|
118 | + if (!$from->empty && !$to->empty && $from->value > $to->value) |
|
119 | + { |
|
115 | 120 | [$from, $to] = [$to, $from]; |
116 | 121 | } |
117 | 122 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function __construct(array $items = []) |
37 | 37 | { |
38 | - foreach ($items as $item) { |
|
38 | + foreach ($items as $item){ |
|
39 | 39 | $this->addItem($item); |
40 | 40 | } |
41 | 41 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | $header = new static(); |
51 | 51 | |
52 | 52 | $parts = explode(',', $raw); |
53 | - foreach ($parts as $part) { |
|
53 | + foreach ($parts as $part){ |
|
54 | 54 | $part = trim($part); |
55 | - if ($part !== '') { |
|
55 | + if ($part !== ''){ |
|
56 | 56 | $header->addItem($part); |
57 | 57 | } |
58 | 58 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function getAll(): array |
88 | 88 | { |
89 | - if (!$this->sorted) { |
|
89 | + if (!$this->sorted){ |
|
90 | 90 | /** |
91 | 91 | * Sort item in descending order. |
92 | 92 | */ |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | */ |
106 | 106 | private function addItem($item): void |
107 | 107 | { |
108 | - if (is_scalar($item)) { |
|
108 | + if (is_scalar($item)){ |
|
109 | 109 | $item = AcceptHeaderItem::fromString((string)$item); |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** @var AcceptHeaderItem|array $item */ |
113 | - if (!$item instanceof AcceptHeaderItem) { |
|
113 | + if (!$item instanceof AcceptHeaderItem){ |
|
114 | 114 | throw new AcceptHeaderException(sprintf( |
115 | 115 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
116 | 116 | AcceptHeaderItem::class, |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | $value = strtolower($item->getValue()); |
122 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
122 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){ |
|
123 | 123 | $this->sorted = false; |
124 | 124 | $this->items[$value] = $item; |
125 | 125 | } |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | */ |
135 | 135 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
136 | 136 | { |
137 | - if ($a->getQuality() === $b->getQuality()) { |
|
137 | + if ($a->getQuality() === $b->getQuality()){ |
|
138 | 138 | // If quality are same value with more params has more weight. |
139 | - if (count($a->getParams()) === count($b->getParams())) { |
|
139 | + if (count($a->getParams()) === count($b->getParams())){ |
|
140 | 140 | // If quality and params then check for specific type or subtype. |
141 | 141 | // Means */* or * has less weight. |
142 | 142 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | private static function compareValue(string $a, string $b): int |
156 | 156 | { |
157 | 157 | // Check "Accept" headers values with it is type and subtype. |
158 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
158 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false){ |
|
159 | 159 | [$typeA, $subtypeA] = explode('/', $a, 2); |
160 | 160 | [$typeB, $subtypeB] = explode('/', $b, 2); |
161 | 161 | |
162 | - if ($typeA === $typeB) { |
|
162 | + if ($typeA === $typeB){ |
|
163 | 163 | return static::compareAtomic($subtypeA, $subtypeB); |
164 | 164 | } |
165 | 165 | |
@@ -171,23 +171,23 @@ discard block |
||
171 | 171 | |
172 | 172 | private static function compareAtomic(string $a, string $b): int |
173 | 173 | { |
174 | - if (mb_strpos($a, '*/') === 0) { |
|
174 | + if (mb_strpos($a, '*/') === 0){ |
|
175 | 175 | $a = '*'; |
176 | 176 | } |
177 | 177 | |
178 | - if (mb_strpos($b, '*/') === 0) { |
|
178 | + if (mb_strpos($b, '*/') === 0){ |
|
179 | 179 | $b = '*'; |
180 | 180 | } |
181 | 181 | |
182 | - if (strtolower($a) === strtolower($b)) { |
|
182 | + if (strtolower($a) === strtolower($b)){ |
|
183 | 183 | return 0; |
184 | 184 | } |
185 | 185 | |
186 | - if ($a === '*') { |
|
186 | + if ($a === '*'){ |
|
187 | 187 | return -1; |
188 | 188 | } |
189 | 189 | |
190 | - if ($b === '*') { |
|
190 | + if ($b === '*'){ |
|
191 | 191 | return 1; |
192 | 192 | } |
193 | 193 |
@@ -35,7 +35,8 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function __construct(array $items = []) |
37 | 37 | { |
38 | - foreach ($items as $item) { |
|
38 | + foreach ($items as $item) |
|
39 | + { |
|
39 | 40 | $this->addItem($item); |
40 | 41 | } |
41 | 42 | } |
@@ -50,9 +51,11 @@ discard block |
||
50 | 51 | $header = new static(); |
51 | 52 | |
52 | 53 | $parts = explode(',', $raw); |
53 | - foreach ($parts as $part) { |
|
54 | + foreach ($parts as $part) |
|
55 | + { |
|
54 | 56 | $part = trim($part); |
55 | - if ($part !== '') { |
|
57 | + if ($part !== '') |
|
58 | + { |
|
56 | 59 | $header->addItem($part); |
57 | 60 | } |
58 | 61 | } |
@@ -86,7 +89,8 @@ discard block |
||
86 | 89 | */ |
87 | 90 | public function getAll(): array |
88 | 91 | { |
89 | - if (!$this->sorted) { |
|
92 | + if (!$this->sorted) |
|
93 | + { |
|
90 | 94 | /** |
91 | 95 | * Sort item in descending order. |
92 | 96 | */ |
@@ -105,12 +109,14 @@ discard block |
||
105 | 109 | */ |
106 | 110 | private function addItem($item): void |
107 | 111 | { |
108 | - if (is_scalar($item)) { |
|
112 | + if (is_scalar($item)) |
|
113 | + { |
|
109 | 114 | $item = AcceptHeaderItem::fromString((string)$item); |
110 | 115 | } |
111 | 116 | |
112 | 117 | /** @var AcceptHeaderItem|array $item */ |
113 | - if (!$item instanceof AcceptHeaderItem) { |
|
118 | + if (!$item instanceof AcceptHeaderItem) |
|
119 | + { |
|
114 | 120 | throw new AcceptHeaderException(sprintf( |
115 | 121 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
116 | 122 | AcceptHeaderItem::class, |
@@ -119,7 +125,8 @@ discard block |
||
119 | 125 | } |
120 | 126 | |
121 | 127 | $value = strtolower($item->getValue()); |
122 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
128 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) |
|
129 | + { |
|
123 | 130 | $this->sorted = false; |
124 | 131 | $this->items[$value] = $item; |
125 | 132 | } |
@@ -134,9 +141,11 @@ discard block |
||
134 | 141 | */ |
135 | 142 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
136 | 143 | { |
137 | - if ($a->getQuality() === $b->getQuality()) { |
|
144 | + if ($a->getQuality() === $b->getQuality()) |
|
145 | + { |
|
138 | 146 | // If quality are same value with more params has more weight. |
139 | - if (count($a->getParams()) === count($b->getParams())) { |
|
147 | + if (count($a->getParams()) === count($b->getParams())) |
|
148 | + { |
|
140 | 149 | // If quality and params then check for specific type or subtype. |
141 | 150 | // Means */* or * has less weight. |
142 | 151 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -155,11 +164,13 @@ discard block |
||
155 | 164 | private static function compareValue(string $a, string $b): int |
156 | 165 | { |
157 | 166 | // Check "Accept" headers values with it is type and subtype. |
158 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
167 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false) |
|
168 | + { |
|
159 | 169 | [$typeA, $subtypeA] = explode('/', $a, 2); |
160 | 170 | [$typeB, $subtypeB] = explode('/', $b, 2); |
161 | 171 | |
162 | - if ($typeA === $typeB) { |
|
172 | + if ($typeA === $typeB) |
|
173 | + { |
|
163 | 174 | return static::compareAtomic($subtypeA, $subtypeB); |
164 | 175 | } |
165 | 176 | |
@@ -171,23 +182,28 @@ discard block |
||
171 | 182 | |
172 | 183 | private static function compareAtomic(string $a, string $b): int |
173 | 184 | { |
174 | - if (mb_strpos($a, '*/') === 0) { |
|
185 | + if (mb_strpos($a, '*/') === 0) |
|
186 | + { |
|
175 | 187 | $a = '*'; |
176 | 188 | } |
177 | 189 | |
178 | - if (mb_strpos($b, '*/') === 0) { |
|
190 | + if (mb_strpos($b, '*/') === 0) |
|
191 | + { |
|
179 | 192 | $b = '*'; |
180 | 193 | } |
181 | 194 | |
182 | - if (strtolower($a) === strtolower($b)) { |
|
195 | + if (strtolower($a) === strtolower($b)) |
|
196 | + { |
|
183 | 197 | return 0; |
184 | 198 | } |
185 | 199 | |
186 | - if ($a === '*') { |
|
200 | + if ($a === '*') |
|
201 | + { |
|
187 | 202 | return -1; |
188 | 203 | } |
189 | 204 | |
190 | - if ($b === '*') { |
|
205 | + if ($b === '*') |
|
206 | + { |
|
191 | 207 | return 1; |
192 | 208 | } |
193 | 209 |
@@ -65,12 +65,14 @@ |
||
65 | 65 | */ |
66 | 66 | public function handle(Request $request): Response |
67 | 67 | { |
68 | - if (empty($this->handler)) { |
|
68 | + if (empty($this->handler)) |
|
69 | + { |
|
69 | 70 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
70 | 71 | } |
71 | 72 | |
72 | 73 | $position = $this->position++; |
73 | - if (isset($this->middleware[$position])) { |
|
74 | + if (isset($this->middleware[$position])) |
|
75 | + { |
|
74 | 76 | return $this->middleware[$position]->process($request, $this); |
75 | 77 | } |
76 | 78 |
@@ -34,11 +34,11 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct(?int $code = null, string $message = '', ?Throwable $previous = null) |
36 | 36 | { |
37 | - if (empty($code) && empty($this->code)) { |
|
37 | + if (empty($code) && empty($this->code)){ |
|
38 | 38 | $code = self::BAD_DATA; |
39 | 39 | } |
40 | 40 | |
41 | - if (empty($message)) { |
|
41 | + if (empty($message)){ |
|
42 | 42 | $message = "Http Error - {$code}"; |
43 | 43 | } |
44 | 44 |
@@ -34,11 +34,13 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct(?int $code = null, string $message = '', ?Throwable $previous = null) |
36 | 36 | { |
37 | - if (empty($code) && empty($this->code)) { |
|
37 | + if (empty($code) && empty($this->code)) |
|
38 | + { |
|
38 | 39 | $code = self::BAD_DATA; |
39 | 40 | } |
40 | 41 | |
41 | - if (empty($message)) { |
|
42 | + if (empty($message)) |
|
43 | + { |
|
42 | 44 | $message = "Http Error - {$code}"; |
43 | 45 | } |
44 | 46 |