@@ -63,8 +63,8 @@ |
||
63 | 63 | #[\ReturnTypeWillChange] |
64 | 64 | public function gc($maxlifetime) |
65 | 65 | { |
66 | - foreach ($this->files->getFiles($this->directory) as $filename) { |
|
67 | - if ($this->files->time($filename) < time() - $maxlifetime) { |
|
66 | + foreach ($this->files->getFiles($this->directory) as $filename){ |
|
67 | + if ($this->files->time($filename) < time() - $maxlifetime){ |
|
68 | 68 | $this->files->delete($filename); |
69 | 69 | } |
70 | 70 | } |
@@ -63,8 +63,10 @@ |
||
63 | 63 | #[\ReturnTypeWillChange] |
64 | 64 | public function gc($maxlifetime) |
65 | 65 | { |
66 | - foreach ($this->files->getFiles($this->directory) as $filename) { |
|
67 | - if ($this->files->time($filename) < time() - $maxlifetime) { |
|
66 | + foreach ($this->files->getFiles($this->directory) as $filename) |
|
67 | + { |
|
68 | + if ($this->files->time($filename) < time() - $maxlifetime) |
|
69 | + { |
|
68 | 70 | $this->files->delete($filename); |
69 | 71 | } |
70 | 72 | } |
@@ -72,7 +72,7 @@ |
||
72 | 72 | #[\ReturnTypeWillChange] |
73 | 73 | public function offsetGet($offset) |
74 | 74 | { |
75 | - if (!$this->offsetExists($offset)) { |
|
75 | + if (!$this->offsetExists($offset)){ |
|
76 | 76 | throw new ConfigException("Undefined configuration key '{$offset}'"); |
77 | 77 | } |
78 | 78 |
@@ -72,7 +72,8 @@ |
||
72 | 72 | #[\ReturnTypeWillChange] |
73 | 73 | public function offsetGet($offset) |
74 | 74 | { |
75 | - if (!$this->offsetExists($offset)) { |
|
75 | + if (!$this->offsetExists($offset)) |
|
76 | + { |
|
76 | 77 | throw new ConfigException("Undefined configuration key '{$offset}'"); |
77 | 78 | } |
78 | 79 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function getIterator(): \Traversable |
48 | 48 | { |
49 | - while ($n = $this->next()) { |
|
49 | + while ($n = $this->next()){ |
|
50 | 50 | yield $n; |
51 | 51 | } |
52 | 52 | } |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function next() |
66 | 66 | { |
67 | - if ($this->replay !== []) { |
|
67 | + if ($this->replay !== []){ |
|
68 | 68 | $n = array_shift($this->replay); |
69 | - } else { |
|
69 | + }else{ |
|
70 | 70 | $n = $this->generator->current(); |
71 | - if ($n === null) { |
|
71 | + if ($n === null){ |
|
72 | 72 | return null; |
73 | 73 | } |
74 | 74 | $this->generator->next(); |
75 | 75 | $this->buffer[] = $n; |
76 | 76 | } |
77 | 77 | |
78 | - if ($n !== null) { |
|
78 | + if ($n !== null){ |
|
79 | 79 | $this->offset = $n->offset; |
80 | 80 | } |
81 | 81 | |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | public function nextBytes(): string |
91 | 91 | { |
92 | 92 | $result = ''; |
93 | - while ($n = $this->next()) { |
|
94 | - if ($n instanceof Byte) { |
|
93 | + while ($n = $this->next()){ |
|
94 | + if ($n instanceof Byte){ |
|
95 | 95 | $result .= $n->char; |
96 | - } else { |
|
96 | + }else{ |
|
97 | 97 | break; |
98 | 98 | } |
99 | 99 | } |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function lookahead() |
108 | 108 | { |
109 | - if ($this->replay !== []) { |
|
109 | + if ($this->replay !== []){ |
|
110 | 110 | return $this->replay[0]; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $n = $this->next(); |
114 | - if ($n !== null) { |
|
114 | + if ($n !== null){ |
|
115 | 115 | array_unshift($this->replay, $n); |
116 | 116 | } |
117 | 117 | |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | { |
129 | 129 | $result = ''; |
130 | 130 | $replay = []; |
131 | - for ($i = 0; $i < $size; $i++) { |
|
131 | + for ($i = 0; $i < $size; $i++){ |
|
132 | 132 | $n = $this->next(); |
133 | - if ($n !== null) { |
|
133 | + if ($n !== null){ |
|
134 | 134 | $replay[] = $n; |
135 | 135 | } |
136 | 136 | |
137 | - if (!$n instanceof Byte) { |
|
137 | + if (!$n instanceof Byte){ |
|
138 | 138 | break; |
139 | 139 | } |
140 | 140 | |
141 | 141 | $result .= $n->char; |
142 | 142 | } |
143 | 143 | |
144 | - foreach (array_reverse($replay) as $n) { |
|
144 | + foreach (array_reverse($replay) as $n){ |
|
145 | 145 | array_unshift($this->replay, $n); |
146 | 146 | } |
147 | 147 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function replay(int $offset): void |
157 | 157 | { |
158 | - foreach ($this->buffer as $n) { |
|
159 | - if ($n->offset > $offset) { |
|
158 | + foreach ($this->buffer as $n){ |
|
159 | + if ($n->offset > $offset){ |
|
160 | 160 | $this->replay[] = $n; |
161 | 161 | } |
162 | 162 | } |
@@ -46,7 +46,8 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function getIterator(): \Traversable |
48 | 48 | { |
49 | - while ($n = $this->next()) { |
|
49 | + while ($n = $this->next()) |
|
50 | + { |
|
50 | 51 | yield $n; |
51 | 52 | } |
52 | 53 | } |
@@ -64,18 +65,23 @@ discard block |
||
64 | 65 | */ |
65 | 66 | public function next() |
66 | 67 | { |
67 | - if ($this->replay !== []) { |
|
68 | + if ($this->replay !== []) |
|
69 | + { |
|
68 | 70 | $n = array_shift($this->replay); |
69 | - } else { |
|
71 | + } |
|
72 | + else |
|
73 | + { |
|
70 | 74 | $n = $this->generator->current(); |
71 | - if ($n === null) { |
|
75 | + if ($n === null) |
|
76 | + { |
|
72 | 77 | return null; |
73 | 78 | } |
74 | 79 | $this->generator->next(); |
75 | 80 | $this->buffer[] = $n; |
76 | 81 | } |
77 | 82 | |
78 | - if ($n !== null) { |
|
83 | + if ($n !== null) |
|
84 | + { |
|
79 | 85 | $this->offset = $n->offset; |
80 | 86 | } |
81 | 87 | |
@@ -90,10 +96,14 @@ discard block |
||
90 | 96 | public function nextBytes(): string |
91 | 97 | { |
92 | 98 | $result = ''; |
93 | - while ($n = $this->next()) { |
|
94 | - if ($n instanceof Byte) { |
|
99 | + while ($n = $this->next()) |
|
100 | + { |
|
101 | + if ($n instanceof Byte) |
|
102 | + { |
|
95 | 103 | $result .= $n->char; |
96 | - } else { |
|
104 | + } |
|
105 | + else |
|
106 | + { |
|
97 | 107 | break; |
98 | 108 | } |
99 | 109 | } |
@@ -106,12 +116,14 @@ discard block |
||
106 | 116 | */ |
107 | 117 | public function lookahead() |
108 | 118 | { |
109 | - if ($this->replay !== []) { |
|
119 | + if ($this->replay !== []) |
|
120 | + { |
|
110 | 121 | return $this->replay[0]; |
111 | 122 | } |
112 | 123 | |
113 | 124 | $n = $this->next(); |
114 | - if ($n !== null) { |
|
125 | + if ($n !== null) |
|
126 | + { |
|
115 | 127 | array_unshift($this->replay, $n); |
116 | 128 | } |
117 | 129 | |
@@ -128,20 +140,24 @@ discard block |
||
128 | 140 | { |
129 | 141 | $result = ''; |
130 | 142 | $replay = []; |
131 | - for ($i = 0; $i < $size; $i++) { |
|
143 | + for ($i = 0; $i < $size; $i++) |
|
144 | + { |
|
132 | 145 | $n = $this->next(); |
133 | - if ($n !== null) { |
|
146 | + if ($n !== null) |
|
147 | + { |
|
134 | 148 | $replay[] = $n; |
135 | 149 | } |
136 | 150 | |
137 | - if (!$n instanceof Byte) { |
|
151 | + if (!$n instanceof Byte) |
|
152 | + { |
|
138 | 153 | break; |
139 | 154 | } |
140 | 155 | |
141 | 156 | $result .= $n->char; |
142 | 157 | } |
143 | 158 | |
144 | - foreach (array_reverse($replay) as $n) { |
|
159 | + foreach (array_reverse($replay) as $n) |
|
160 | + { |
|
145 | 161 | array_unshift($this->replay, $n); |
146 | 162 | } |
147 | 163 | |
@@ -155,8 +171,10 @@ discard block |
||
155 | 171 | */ |
156 | 172 | public function replay(int $offset): void |
157 | 173 | { |
158 | - foreach ($this->buffer as $n) { |
|
159 | - if ($n->offset > $offset) { |
|
174 | + foreach ($this->buffer as $n) |
|
175 | + { |
|
176 | + if ($n->offset > $offset) |
|
177 | + { |
|
160 | 178 | $this->replay[] = $n; |
161 | 179 | } |
162 | 180 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | array $schema, |
91 | 91 | ValidatorInterface $validator, |
92 | 92 | ErrorMapper $errorMapper |
93 | - ) { |
|
93 | + ){ |
|
94 | 94 | parent::__construct($data, $schema); |
95 | 95 | |
96 | 96 | $this->mappings = $schema[FilterProvider::MAPPING] ?? []; |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function getErrors(): array |
153 | 153 | { |
154 | - if ($this->errors === null) { |
|
154 | + if ($this->errors === null){ |
|
155 | 155 | $this->errors = []; |
156 | - foreach ($this->validator->withData($this)->getErrors() as $field => $error) { |
|
157 | - if (is_string($error) && Translator::isMessage($error)) { |
|
156 | + foreach ($this->validator->withData($this)->getErrors() as $field => $error){ |
|
157 | + if (is_string($error) && Translator::isMessage($error)){ |
|
158 | 158 | // translate error message |
159 | 159 | $error = $this->say($error); |
160 | 160 | } |
@@ -195,32 +195,32 @@ discard block |
||
195 | 195 | */ |
196 | 196 | protected function validateNested(array $errors): array |
197 | 197 | { |
198 | - foreach ($this->getFields(false) as $index => $value) { |
|
199 | - if (isset($errors[$index])) { |
|
198 | + foreach ($this->getFields(false) as $index => $value){ |
|
199 | + if (isset($errors[$index])){ |
|
200 | 200 | //Invalid on parent level |
201 | 201 | continue; |
202 | 202 | } |
203 | 203 | |
204 | - if ($value instanceof FilterInterface) { |
|
205 | - if ($this->isOptional($index) && !$this->hasBeenPassed($index)) { |
|
204 | + if ($value instanceof FilterInterface){ |
|
205 | + if ($this->isOptional($index) && !$this->hasBeenPassed($index)){ |
|
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | |
209 | - if (!$value->isValid()) { |
|
209 | + if (!$value->isValid()){ |
|
210 | 210 | $errors[$index] = $value->getErrors(); |
211 | 211 | continue; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | 215 | //Array of nested entities for validation |
216 | - if (is_iterable($value)) { |
|
217 | - foreach ($value as $nIndex => $nValue) { |
|
218 | - if ($nValue instanceof FilterInterface) { |
|
219 | - if ($this->isOptional($nIndex) && !$this->hasBeenPassed($nIndex)) { |
|
216 | + if (is_iterable($value)){ |
|
217 | + foreach ($value as $nIndex => $nValue){ |
|
218 | + if ($nValue instanceof FilterInterface){ |
|
219 | + if ($this->isOptional($nIndex) && !$this->hasBeenPassed($nIndex)){ |
|
220 | 220 | continue; |
221 | 221 | } |
222 | 222 | |
223 | - if (!$nValue->isValid()) { |
|
223 | + if (!$nValue->isValid()){ |
|
224 | 224 | $errors[$index][$nIndex] = $nValue->getErrors(); |
225 | 225 | } |
226 | 226 | } |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | { |
255 | 255 | $value = $this->getField((string)$field); |
256 | 256 | |
257 | - if ($value === null) { |
|
257 | + if ($value === null){ |
|
258 | 258 | return false; |
259 | 259 | } |
260 | 260 | |
261 | - if ($value instanceof FilterInterface) { |
|
261 | + if ($value instanceof FilterInterface){ |
|
262 | 262 | return $value->getValue() !== []; |
263 | 263 | } |
264 | 264 |
@@ -151,10 +151,13 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function getErrors(): array |
153 | 153 | { |
154 | - if ($this->errors === null) { |
|
154 | + if ($this->errors === null) |
|
155 | + { |
|
155 | 156 | $this->errors = []; |
156 | - foreach ($this->validator->withData($this)->getErrors() as $field => $error) { |
|
157 | - if (is_string($error) && Translator::isMessage($error)) { |
|
157 | + foreach ($this->validator->withData($this)->getErrors() as $field => $error) |
|
158 | + { |
|
159 | + if (is_string($error) && Translator::isMessage($error)) |
|
160 | + { |
|
158 | 161 | // translate error message |
159 | 162 | $error = $this->say($error); |
160 | 163 | } |
@@ -195,32 +198,42 @@ discard block |
||
195 | 198 | */ |
196 | 199 | protected function validateNested(array $errors): array |
197 | 200 | { |
198 | - foreach ($this->getFields(false) as $index => $value) { |
|
199 | - if (isset($errors[$index])) { |
|
201 | + foreach ($this->getFields(false) as $index => $value) |
|
202 | + { |
|
203 | + if (isset($errors[$index])) |
|
204 | + { |
|
200 | 205 | //Invalid on parent level |
201 | 206 | continue; |
202 | 207 | } |
203 | 208 | |
204 | - if ($value instanceof FilterInterface) { |
|
205 | - if ($this->isOptional($index) && !$this->hasBeenPassed($index)) { |
|
209 | + if ($value instanceof FilterInterface) |
|
210 | + { |
|
211 | + if ($this->isOptional($index) && !$this->hasBeenPassed($index)) |
|
212 | + { |
|
206 | 213 | continue; |
207 | 214 | } |
208 | 215 | |
209 | - if (!$value->isValid()) { |
|
216 | + if (!$value->isValid()) |
|
217 | + { |
|
210 | 218 | $errors[$index] = $value->getErrors(); |
211 | 219 | continue; |
212 | 220 | } |
213 | 221 | } |
214 | 222 | |
215 | 223 | //Array of nested entities for validation |
216 | - if (is_iterable($value)) { |
|
217 | - foreach ($value as $nIndex => $nValue) { |
|
218 | - if ($nValue instanceof FilterInterface) { |
|
219 | - if ($this->isOptional($nIndex) && !$this->hasBeenPassed($nIndex)) { |
|
224 | + if (is_iterable($value)) |
|
225 | + { |
|
226 | + foreach ($value as $nIndex => $nValue) |
|
227 | + { |
|
228 | + if ($nValue instanceof FilterInterface) |
|
229 | + { |
|
230 | + if ($this->isOptional($nIndex) && !$this->hasBeenPassed($nIndex)) |
|
231 | + { |
|
220 | 232 | continue; |
221 | 233 | } |
222 | 234 | |
223 | - if (!$nValue->isValid()) { |
|
235 | + if (!$nValue->isValid()) |
|
236 | + { |
|
224 | 237 | $errors[$index][$nIndex] = $nValue->getErrors(); |
225 | 238 | } |
226 | 239 | } |
@@ -254,11 +267,13 @@ discard block |
||
254 | 267 | { |
255 | 268 | $value = $this->getField((string)$field); |
256 | 269 | |
257 | - if ($value === null) { |
|
270 | + if ($value === null) |
|
271 | + { |
|
258 | 272 | return false; |
259 | 273 | } |
260 | 274 | |
261 | - if ($value instanceof FilterInterface) { |
|
275 | + if ($value instanceof FilterInterface) |
|
276 | + { |
|
262 | 277 | return $value->getValue() !== []; |
263 | 278 | } |
264 | 279 |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function bootResolvers(array $config): void |
73 | 73 | { |
74 | - foreach ($config['resolvers'] ?? [] as $name => $child) { |
|
75 | - if (!\is_string($name)) { |
|
74 | + foreach ($config['resolvers'] ?? [] as $name => $child){ |
|
75 | + if (!\is_string($name)){ |
|
76 | 76 | throw new InvalidArgumentException( |
77 | 77 | \vsprintf('Distribution driver config key must be a string, but %s given', [ |
78 | 78 | \get_debug_type($child), |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
83 | - if (!\is_array($child)) { |
|
83 | + if (!\is_array($child)){ |
|
84 | 84 | throw new InvalidArgumentException( |
85 | 85 | \vsprintf('Distribution driver config `%s` must be an array, but %s given', [ |
86 | 86 | $name, |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | { |
101 | 101 | $default = $config['default'] ?? null; |
102 | 102 | |
103 | - if ($default !== null) { |
|
103 | + if ($default !== null){ |
|
104 | 104 | // Validate config |
105 | - if (!\is_string($default)) { |
|
105 | + if (!\is_string($default)){ |
|
106 | 106 | throw new InvalidArgumentException( |
107 | 107 | \vsprintf('Distribution config default driver must be a string, but %s given', [ |
108 | 108 | \get_debug_type($default), |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | */ |
122 | 122 | private function createResolver(string $name, array $config): UriResolverInterface |
123 | 123 | { |
124 | - if (!isset($config['type']) || !\is_string($config['type'])) { |
|
124 | + if (!isset($config['type']) || !\is_string($config['type'])){ |
|
125 | 125 | throw $this->invalidConfigKey($name, 'type', 'string'); |
126 | 126 | } |
127 | 127 | |
128 | 128 | $type = $config['type']; |
129 | 129 | |
130 | - switch ($type) { |
|
130 | + switch ($type){ |
|
131 | 131 | case 'static': |
132 | 132 | return $this->createStaticResolver($name, $config); |
133 | 133 | |
@@ -150,17 +150,17 @@ discard block |
||
150 | 150 | */ |
151 | 151 | private function createCustomResolver(string $type, string $name, array $config): UriResolverInterface |
152 | 152 | { |
153 | - if (!\is_subclass_of($type, UriResolverInterface::class, true)) { |
|
153 | + if (!\is_subclass_of($type, UriResolverInterface::class, true)){ |
|
154 | 154 | throw $this->invalidConfigKey($name, 'type', UriResolverInterface::class); |
155 | 155 | } |
156 | 156 | |
157 | - if (isset($config['options']) && !\is_array($config['options'])) { |
|
157 | + if (isset($config['options']) && !\is_array($config['options'])){ |
|
158 | 158 | throw $this->invalidConfigKey($name, 'options', 'array'); |
159 | 159 | } |
160 | 160 | |
161 | - try { |
|
161 | + try{ |
|
162 | 162 | return new $type(...\array_values($config['options'] ?? [])); |
163 | - } catch (\Throwable $e) { |
|
163 | + }catch (\Throwable $e){ |
|
164 | 164 | $message = 'An error occurred while resolver `%s` initializing: %s'; |
165 | 165 | throw new InvalidArgumentException(\sprintf($message, $name, $e->getMessage()), 0, $e); |
166 | 166 | } |
@@ -174,36 +174,36 @@ discard block |
||
174 | 174 | private function createS3Resolver(string $name, array $config): UriResolverInterface |
175 | 175 | { |
176 | 176 | // Required config options |
177 | - if (!isset($config['region']) || !\is_string($config['region'])) { |
|
177 | + if (!isset($config['region']) || !\is_string($config['region'])){ |
|
178 | 178 | throw $this->invalidConfigKey($name, 'region', 'string'); |
179 | 179 | } |
180 | 180 | |
181 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
181 | + if (!isset($config['key']) || !\is_string($config['key'])){ |
|
182 | 182 | throw $this->invalidConfigKey($name, 'key', 'string'); |
183 | 183 | } |
184 | 184 | |
185 | - if (!isset($config['secret']) || !\is_string($config['secret'])) { |
|
185 | + if (!isset($config['secret']) || !\is_string($config['secret'])){ |
|
186 | 186 | throw $this->invalidConfigKey($name, 'secret', 'string'); |
187 | 187 | } |
188 | 188 | |
189 | - if (!isset($config['bucket']) || !\is_string($config['bucket'])) { |
|
189 | + if (!isset($config['bucket']) || !\is_string($config['bucket'])){ |
|
190 | 190 | throw $this->invalidConfigKey($name, 'bucket', 'string'); |
191 | 191 | } |
192 | 192 | |
193 | 193 | // Optional config options |
194 | - if (!\is_string($config['prefix'] ?? '')) { |
|
194 | + if (!\is_string($config['prefix'] ?? '')){ |
|
195 | 195 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
196 | 196 | } |
197 | 197 | |
198 | - if (!\is_string($config['version'] ?? '')) { |
|
198 | + if (!\is_string($config['version'] ?? '')){ |
|
199 | 199 | throw $this->invalidConfigKey($name, 'version', 'string or null'); |
200 | 200 | } |
201 | 201 | |
202 | - if (!\is_string($config['token'] ?? '')) { |
|
202 | + if (!\is_string($config['token'] ?? '')){ |
|
203 | 203 | throw $this->invalidConfigKey($name, 'token', 'string or null'); |
204 | 204 | } |
205 | 205 | |
206 | - if (!\is_int($config['expires'] ?? 0)) { |
|
206 | + if (!\is_int($config['expires'] ?? 0)){ |
|
207 | 207 | throw $this->invalidConfigKey($name, 'expires', 'positive int (unix timestamp)'); |
208 | 208 | } |
209 | 209 | |
@@ -233,19 +233,19 @@ discard block |
||
233 | 233 | */ |
234 | 234 | private function createCloudFrontResolver(string $name, array $config): UriResolverInterface |
235 | 235 | { |
236 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
236 | + if (!isset($config['key']) || !\is_string($config['key'])){ |
|
237 | 237 | throw $this->invalidConfigKey($name, 'key', 'string'); |
238 | 238 | } |
239 | 239 | |
240 | - if (!isset($config['private']) || !\is_string($config['private'])) { |
|
240 | + if (!isset($config['private']) || !\is_string($config['private'])){ |
|
241 | 241 | throw $this->invalidConfigKey($name, 'private', 'string value or path to key file'); |
242 | 242 | } |
243 | 243 | |
244 | - if (!isset($config['domain']) || !\is_string($config['domain'])) { |
|
244 | + if (!isset($config['domain']) || !\is_string($config['domain'])){ |
|
245 | 245 | throw $this->invalidConfigKey($name, 'domain', 'string'); |
246 | 246 | } |
247 | 247 | |
248 | - if (!\is_string($config['prefix'] ?? '')) { |
|
248 | + if (!\is_string($config['prefix'] ?? '')){ |
|
249 | 249 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
250 | 250 | } |
251 | 251 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | private function createStaticResolver(string $name, array $config): UriResolverInterface |
266 | 266 | { |
267 | - if (!isset($config['uri']) || !\is_string($config['uri'])) { |
|
267 | + if (!isset($config['uri']) || !\is_string($config['uri'])){ |
|
268 | 268 | throw $this->invalidConfigKey($name, 'uri', 'string'); |
269 | 269 | } |
270 | 270 | |
@@ -279,17 +279,17 @@ discard block |
||
279 | 279 | */ |
280 | 280 | private function createUri(string $name, string $uri, array $config): UriInterface |
281 | 281 | { |
282 | - if (!\is_string($config['factory'] ?? '')) { |
|
282 | + if (!\is_string($config['factory'] ?? '')){ |
|
283 | 283 | throw $this->invalidConfigKey($name, 'factory', 'string (PSR-7 uri factory implementation)'); |
284 | 284 | } |
285 | 285 | |
286 | - switch (true) { |
|
286 | + switch (true){ |
|
287 | 287 | case isset($config['factory']): |
288 | 288 | /** @var UriFactoryInterface $factory */ |
289 | 289 | $factory = new $config['factory'](); |
290 | 290 | |
291 | - if (!$factory instanceof UriFactoryInterface) { |
|
292 | - $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 ' . |
|
291 | + if (!$factory instanceof UriFactoryInterface){ |
|
292 | + $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 '. |
|
293 | 293 | 'uri factory implementation, but `%s` given'; |
294 | 294 | throw new InvalidArgumentException(\sprintf($message, $name, $config['factory'])); |
295 | 295 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | return new GuzzleUri($uri); |
304 | 304 | |
305 | 305 | default: |
306 | - $message = 'Can not resolve available PSR-7 UriFactory implementation; ' . |
|
306 | + $message = 'Can not resolve available PSR-7 UriFactory implementation; '. |
|
307 | 307 | 'Please define `factory` config section in `%s` distribution driver config'; |
308 | 308 | throw new InvalidArgumentException(\sprintf($message, $name)); |
309 | 309 | } |
@@ -71,8 +71,10 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function bootResolvers(array $config): void |
73 | 73 | { |
74 | - foreach ($config['resolvers'] ?? [] as $name => $child) { |
|
75 | - if (!\is_string($name)) { |
|
74 | + foreach ($config['resolvers'] ?? [] as $name => $child) |
|
75 | + { |
|
76 | + if (!\is_string($name)) |
|
77 | + { |
|
76 | 78 | throw new InvalidArgumentException( |
77 | 79 | \vsprintf('Distribution driver config key must be a string, but %s given', [ |
78 | 80 | \get_debug_type($child), |
@@ -80,7 +82,8 @@ discard block |
||
80 | 82 | ); |
81 | 83 | } |
82 | 84 | |
83 | - if (!\is_array($child)) { |
|
85 | + if (!\is_array($child)) |
|
86 | + { |
|
84 | 87 | throw new InvalidArgumentException( |
85 | 88 | \vsprintf('Distribution driver config `%s` must be an array, but %s given', [ |
86 | 89 | $name, |
@@ -100,9 +103,11 @@ discard block |
||
100 | 103 | { |
101 | 104 | $default = $config['default'] ?? null; |
102 | 105 | |
103 | - if ($default !== null) { |
|
106 | + if ($default !== null) |
|
107 | + { |
|
104 | 108 | // Validate config |
105 | - if (!\is_string($default)) { |
|
109 | + if (!\is_string($default)) |
|
110 | + { |
|
106 | 111 | throw new InvalidArgumentException( |
107 | 112 | \vsprintf('Distribution config default driver must be a string, but %s given', [ |
108 | 113 | \get_debug_type($default), |
@@ -121,13 +126,15 @@ discard block |
||
121 | 126 | */ |
122 | 127 | private function createResolver(string $name, array $config): UriResolverInterface |
123 | 128 | { |
124 | - if (!isset($config['type']) || !\is_string($config['type'])) { |
|
129 | + if (!isset($config['type']) || !\is_string($config['type'])) |
|
130 | + { |
|
125 | 131 | throw $this->invalidConfigKey($name, 'type', 'string'); |
126 | 132 | } |
127 | 133 | |
128 | 134 | $type = $config['type']; |
129 | 135 | |
130 | - switch ($type) { |
|
136 | + switch ($type) |
|
137 | + { |
|
131 | 138 | case 'static': |
132 | 139 | return $this->createStaticResolver($name, $config); |
133 | 140 | |
@@ -150,17 +157,22 @@ discard block |
||
150 | 157 | */ |
151 | 158 | private function createCustomResolver(string $type, string $name, array $config): UriResolverInterface |
152 | 159 | { |
153 | - if (!\is_subclass_of($type, UriResolverInterface::class, true)) { |
|
160 | + if (!\is_subclass_of($type, UriResolverInterface::class, true)) |
|
161 | + { |
|
154 | 162 | throw $this->invalidConfigKey($name, 'type', UriResolverInterface::class); |
155 | 163 | } |
156 | 164 | |
157 | - if (isset($config['options']) && !\is_array($config['options'])) { |
|
165 | + if (isset($config['options']) && !\is_array($config['options'])) |
|
166 | + { |
|
158 | 167 | throw $this->invalidConfigKey($name, 'options', 'array'); |
159 | 168 | } |
160 | 169 | |
161 | - try { |
|
170 | + try |
|
171 | + { |
|
162 | 172 | return new $type(...\array_values($config['options'] ?? [])); |
163 | - } catch (\Throwable $e) { |
|
173 | + } |
|
174 | + catch (\Throwable $e) |
|
175 | + { |
|
164 | 176 | $message = 'An error occurred while resolver `%s` initializing: %s'; |
165 | 177 | throw new InvalidArgumentException(\sprintf($message, $name, $e->getMessage()), 0, $e); |
166 | 178 | } |
@@ -174,36 +186,44 @@ discard block |
||
174 | 186 | private function createS3Resolver(string $name, array $config): UriResolverInterface |
175 | 187 | { |
176 | 188 | // Required config options |
177 | - if (!isset($config['region']) || !\is_string($config['region'])) { |
|
189 | + if (!isset($config['region']) || !\is_string($config['region'])) |
|
190 | + { |
|
178 | 191 | throw $this->invalidConfigKey($name, 'region', 'string'); |
179 | 192 | } |
180 | 193 | |
181 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
194 | + if (!isset($config['key']) || !\is_string($config['key'])) |
|
195 | + { |
|
182 | 196 | throw $this->invalidConfigKey($name, 'key', 'string'); |
183 | 197 | } |
184 | 198 | |
185 | - if (!isset($config['secret']) || !\is_string($config['secret'])) { |
|
199 | + if (!isset($config['secret']) || !\is_string($config['secret'])) |
|
200 | + { |
|
186 | 201 | throw $this->invalidConfigKey($name, 'secret', 'string'); |
187 | 202 | } |
188 | 203 | |
189 | - if (!isset($config['bucket']) || !\is_string($config['bucket'])) { |
|
204 | + if (!isset($config['bucket']) || !\is_string($config['bucket'])) |
|
205 | + { |
|
190 | 206 | throw $this->invalidConfigKey($name, 'bucket', 'string'); |
191 | 207 | } |
192 | 208 | |
193 | 209 | // Optional config options |
194 | - if (!\is_string($config['prefix'] ?? '')) { |
|
210 | + if (!\is_string($config['prefix'] ?? '')) |
|
211 | + { |
|
195 | 212 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
196 | 213 | } |
197 | 214 | |
198 | - if (!\is_string($config['version'] ?? '')) { |
|
215 | + if (!\is_string($config['version'] ?? '')) |
|
216 | + { |
|
199 | 217 | throw $this->invalidConfigKey($name, 'version', 'string or null'); |
200 | 218 | } |
201 | 219 | |
202 | - if (!\is_string($config['token'] ?? '')) { |
|
220 | + if (!\is_string($config['token'] ?? '')) |
|
221 | + { |
|
203 | 222 | throw $this->invalidConfigKey($name, 'token', 'string or null'); |
204 | 223 | } |
205 | 224 | |
206 | - if (!\is_int($config['expires'] ?? 0)) { |
|
225 | + if (!\is_int($config['expires'] ?? 0)) |
|
226 | + { |
|
207 | 227 | throw $this->invalidConfigKey($name, 'expires', 'positive int (unix timestamp)'); |
208 | 228 | } |
209 | 229 | |
@@ -233,19 +253,23 @@ discard block |
||
233 | 253 | */ |
234 | 254 | private function createCloudFrontResolver(string $name, array $config): UriResolverInterface |
235 | 255 | { |
236 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
256 | + if (!isset($config['key']) || !\is_string($config['key'])) |
|
257 | + { |
|
237 | 258 | throw $this->invalidConfigKey($name, 'key', 'string'); |
238 | 259 | } |
239 | 260 | |
240 | - if (!isset($config['private']) || !\is_string($config['private'])) { |
|
261 | + if (!isset($config['private']) || !\is_string($config['private'])) |
|
262 | + { |
|
241 | 263 | throw $this->invalidConfigKey($name, 'private', 'string value or path to key file'); |
242 | 264 | } |
243 | 265 | |
244 | - if (!isset($config['domain']) || !\is_string($config['domain'])) { |
|
266 | + if (!isset($config['domain']) || !\is_string($config['domain'])) |
|
267 | + { |
|
245 | 268 | throw $this->invalidConfigKey($name, 'domain', 'string'); |
246 | 269 | } |
247 | 270 | |
248 | - if (!\is_string($config['prefix'] ?? '')) { |
|
271 | + if (!\is_string($config['prefix'] ?? '')) |
|
272 | + { |
|
249 | 273 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
250 | 274 | } |
251 | 275 | |
@@ -264,7 +288,8 @@ discard block |
||
264 | 288 | */ |
265 | 289 | private function createStaticResolver(string $name, array $config): UriResolverInterface |
266 | 290 | { |
267 | - if (!isset($config['uri']) || !\is_string($config['uri'])) { |
|
291 | + if (!isset($config['uri']) || !\is_string($config['uri'])) |
|
292 | + { |
|
268 | 293 | throw $this->invalidConfigKey($name, 'uri', 'string'); |
269 | 294 | } |
270 | 295 | |
@@ -279,16 +304,19 @@ discard block |
||
279 | 304 | */ |
280 | 305 | private function createUri(string $name, string $uri, array $config): UriInterface |
281 | 306 | { |
282 | - if (!\is_string($config['factory'] ?? '')) { |
|
307 | + if (!\is_string($config['factory'] ?? '')) |
|
308 | + { |
|
283 | 309 | throw $this->invalidConfigKey($name, 'factory', 'string (PSR-7 uri factory implementation)'); |
284 | 310 | } |
285 | 311 | |
286 | - switch (true) { |
|
312 | + switch (true) |
|
313 | + { |
|
287 | 314 | case isset($config['factory']): |
288 | 315 | /** @var UriFactoryInterface $factory */ |
289 | 316 | $factory = new $config['factory'](); |
290 | 317 | |
291 | - if (!$factory instanceof UriFactoryInterface) { |
|
318 | + if (!$factory instanceof UriFactoryInterface) |
|
319 | + { |
|
292 | 320 | $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 ' . |
293 | 321 | 'uri factory implementation, but `%s` given'; |
294 | 322 | throw new InvalidArgumentException(\sprintf($message, $name, $config['factory'])); |
@@ -28,11 +28,11 @@ |
||
28 | 28 | $container->bindSingleton(ReaderInterface::class, function () use ($container) { |
29 | 29 | $factory = new Factory(); |
30 | 30 | |
31 | - if ($container->has(CacheInterface::class)) { |
|
31 | + if ($container->has(CacheInterface::class)){ |
|
32 | 32 | $factory = $factory->withCache( |
33 | 33 | $container->get(CacheInterface::class) |
34 | 34 | ); |
35 | - } elseif ($container->has(CacheItemPoolInterface::class)) { |
|
35 | + } elseif ($container->has(CacheItemPoolInterface::class)){ |
|
36 | 36 | $factory = $factory->withCache( |
37 | 37 | $container->get(CacheItemPoolInterface::class) |
38 | 38 | ); |
@@ -25,14 +25,18 @@ |
||
25 | 25 | */ |
26 | 26 | public function boot(Container $container): void |
27 | 27 | { |
28 | - $container->bindSingleton(ReaderInterface::class, function () use ($container) { |
|
28 | + $container->bindSingleton(ReaderInterface::class, function () use ($container) |
|
29 | + { |
|
29 | 30 | $factory = new Factory(); |
30 | 31 | |
31 | - if ($container->has(CacheInterface::class)) { |
|
32 | + if ($container->has(CacheInterface::class)) |
|
33 | + { |
|
32 | 34 | $factory = $factory->withCache( |
33 | 35 | $container->get(CacheInterface::class) |
34 | 36 | ); |
35 | - } elseif ($container->has(CacheItemPoolInterface::class)) { |
|
37 | + } |
|
38 | + elseif ($container->has(CacheItemPoolInterface::class)) |
|
39 | + { |
|
36 | 40 | $factory = $factory->withCache( |
37 | 41 | $container->get(CacheItemPoolInterface::class) |
38 | 42 | ); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function perform(): void |
28 | 28 | { |
29 | - if (!$this->verifyEnvironment()) { |
|
29 | + if (!$this->verifyEnvironment()){ |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $found = false; |
36 | 36 | $count = $this->option('one') ? 1 : PHP_INT_MAX; |
37 | 37 | |
38 | - while ($count > 0 && ($migration = $this->migrator->run())) { |
|
38 | + while ($count > 0 && ($migration = $this->migrator->run())){ |
|
39 | 39 | $found = true; |
40 | 40 | $count--; |
41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ); |
46 | 46 | } |
47 | 47 | |
48 | - if (!$found) { |
|
48 | + if (!$found){ |
|
49 | 49 | $this->writeln('<fg=red>No outstanding migrations were found.</fg=red>'); |
50 | 50 | } |
51 | 51 | } |
@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function perform(): void |
28 | 28 | { |
29 | - if (!$this->verifyEnvironment()) { |
|
29 | + if (!$this->verifyEnvironment()) |
|
30 | + { |
|
30 | 31 | return; |
31 | 32 | } |
32 | 33 | |
@@ -35,7 +36,8 @@ discard block |
||
35 | 36 | $found = false; |
36 | 37 | $count = $this->option('one') ? 1 : PHP_INT_MAX; |
37 | 38 | |
38 | - while ($count > 0 && ($migration = $this->migrator->run())) { |
|
39 | + while ($count > 0 && ($migration = $this->migrator->run())) |
|
40 | + { |
|
39 | 41 | $found = true; |
40 | 42 | $count--; |
41 | 43 | |
@@ -45,7 +47,8 @@ discard block |
||
45 | 47 | ); |
46 | 48 | } |
47 | 49 | |
48 | - if (!$found) { |
|
50 | + if (!$found) |
|
51 | + { |
|
49 | 52 | $this->writeln('<fg=red>No outstanding migrations were found.</fg=red>'); |
50 | 53 | } |
51 | 54 | } |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | { |
31 | 31 | $this->migrator->configure(); |
32 | 32 | |
33 | - if (empty($this->migrator->getMigrations())) { |
|
33 | + if (empty($this->migrator->getMigrations())){ |
|
34 | 34 | $this->writeln('<comment>No migrations were found.</comment>'); |
35 | 35 | |
36 | 36 | return; |
37 | 37 | } |
38 | 38 | |
39 | 39 | $table = $this->table(['Migration', 'Created at', 'Executed at']); |
40 | - foreach ($this->migrator->getMigrations() as $migration) { |
|
40 | + foreach ($this->migrator->getMigrations() as $migration){ |
|
41 | 41 | $state = $migration->getState(); |
42 | 42 | |
43 | 43 | $table->addRow( |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $state->getTimeCreated()->format('Y-m-d H:i:s'), |
47 | 47 | $state->getStatus() == State::STATUS_PENDING |
48 | 48 | ? self::PENDING |
49 | - : '<info>' . $state->getTimeExecuted()->format('Y-m-d H:i:s') . '</info>', |
|
49 | + : '<info>'.$state->getTimeExecuted()->format('Y-m-d H:i:s').'</info>', |
|
50 | 50 | ] |
51 | 51 | ); |
52 | 52 | } |
@@ -30,14 +30,16 @@ |
||
30 | 30 | { |
31 | 31 | $this->migrator->configure(); |
32 | 32 | |
33 | - if (empty($this->migrator->getMigrations())) { |
|
33 | + if (empty($this->migrator->getMigrations())) |
|
34 | + { |
|
34 | 35 | $this->writeln('<comment>No migrations were found.</comment>'); |
35 | 36 | |
36 | 37 | return; |
37 | 38 | } |
38 | 39 | |
39 | 40 | $table = $this->table(['Migration', 'Created at', 'Executed at']); |
40 | - foreach ($this->migrator->getMigrations() as $migration) { |
|
41 | + foreach ($this->migrator->getMigrations() as $migration) |
|
42 | + { |
|
41 | 43 | $state = $migration->getState(); |
42 | 44 | |
43 | 45 | $table->addRow( |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function perform(): void |
28 | 28 | { |
29 | - if (!$this->verifyEnvironment()) { |
|
29 | + if (!$this->verifyEnvironment()){ |
|
30 | 30 | //Making sure we can safely migrate in this environment |
31 | 31 | return; |
32 | 32 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | $found = false; |
37 | 37 | $count = !$this->option('all') ? 1 : PHP_INT_MAX; |
38 | - while ($count > 0 && ($migration = $this->migrator->rollback())) { |
|
38 | + while ($count > 0 && ($migration = $this->migrator->rollback())){ |
|
39 | 39 | $found = true; |
40 | 40 | $count--; |
41 | 41 | $this->sprintf( |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | ); |
45 | 45 | } |
46 | 46 | |
47 | - if (!$found) { |
|
47 | + if (!$found){ |
|
48 | 48 | $this->writeln('<fg=red>No executed migrations were found.</fg=red>'); |
49 | 49 | } |
50 | 50 | } |
@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function perform(): void |
28 | 28 | { |
29 | - if (!$this->verifyEnvironment()) { |
|
29 | + if (!$this->verifyEnvironment()) |
|
30 | + { |
|
30 | 31 | //Making sure we can safely migrate in this environment |
31 | 32 | return; |
32 | 33 | } |
@@ -35,7 +36,8 @@ discard block |
||
35 | 36 | |
36 | 37 | $found = false; |
37 | 38 | $count = !$this->option('all') ? 1 : PHP_INT_MAX; |
38 | - while ($count > 0 && ($migration = $this->migrator->rollback())) { |
|
39 | + while ($count > 0 && ($migration = $this->migrator->rollback())) |
|
40 | + { |
|
39 | 41 | $found = true; |
40 | 42 | $count--; |
41 | 43 | $this->sprintf( |
@@ -44,7 +46,8 @@ discard block |
||
44 | 46 | ); |
45 | 47 | } |
46 | 48 | |
47 | - if (!$found) { |
|
49 | + if (!$found) |
|
50 | + { |
|
48 | 51 | $this->writeln('<fg=red>No executed migrations were found.</fg=red>'); |
49 | 52 | } |
50 | 53 | } |