@@ -45,7 +45,7 @@ |
||
45 | 45 | ], |
46 | 46 | ]); |
47 | 47 | |
48 | - foreach ($rules as $rule) { |
|
48 | + foreach ($rules as $rule){ |
|
49 | 49 | return $rule->getConditions(); |
50 | 50 | } |
51 | 51 |
@@ -45,7 +45,8 @@ |
||
45 | 45 | ], |
46 | 46 | ]); |
47 | 47 | |
48 | - foreach ($rules as $rule) { |
|
48 | + foreach ($rules as $rule) |
|
49 | + { |
|
49 | 50 | return $rule->getConditions(); |
50 | 51 | } |
51 | 52 |
@@ -167,12 +167,14 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function match(UriInterface $uri, array $defaults): ?array |
169 | 169 | { |
170 | - if (!$this->isCompiled()) { |
|
170 | + if (!$this->isCompiled()) |
|
171 | + { |
|
171 | 172 | $this->compile(); |
172 | 173 | } |
173 | 174 | |
174 | 175 | $matches = []; |
175 | - if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) { |
|
176 | + if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) |
|
177 | + { |
|
176 | 178 | return null; |
177 | 179 | } |
178 | 180 | |
@@ -190,7 +192,8 @@ discard block |
||
190 | 192 | */ |
191 | 193 | public function uri($parameters = [], array $defaults = []): UriInterface |
192 | 194 | { |
193 | - if (!$this->isCompiled()) { |
|
195 | + if (!$this->isCompiled()) |
|
196 | + { |
|
194 | 197 | $this->compile(); |
195 | 198 | } |
196 | 199 | |
@@ -200,8 +203,10 @@ discard block |
||
200 | 203 | $this->fetchOptions($parameters, $query) |
201 | 204 | ); |
202 | 205 | |
203 | - foreach ($this->constrains as $key => $_) { |
|
204 | - if (empty($parameters[$key])) { |
|
206 | + foreach ($this->constrains as $key => $_) |
|
207 | + { |
|
208 | + if (empty($parameters[$key])) |
|
209 | + { |
|
205 | 210 | throw new UriHandlerException("Unable to generate Uri, parameter `{$key}` is missing"); |
206 | 211 | } |
207 | 212 | } |
@@ -227,18 +232,23 @@ discard block |
||
227 | 232 | $allowed = array_keys($this->options); |
228 | 233 | |
229 | 234 | $result = []; |
230 | - foreach ($parameters as $key => $parameter) { |
|
231 | - if (is_numeric($key) && isset($allowed[$key])) { |
|
235 | + foreach ($parameters as $key => $parameter) |
|
236 | + { |
|
237 | + if (is_numeric($key) && isset($allowed[$key])) |
|
238 | + { |
|
232 | 239 | // this segment fetched keys from given parameters either by name or by position |
233 | 240 | $key = $allowed[$key]; |
234 | - } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) { |
|
241 | + } |
|
242 | + elseif (!array_key_exists($key, $this->options) && is_array($parameters)) |
|
243 | + { |
|
235 | 244 | // all additional parameters given in array form can be glued to query string |
236 | 245 | $query[$key] = $parameter; |
237 | 246 | continue; |
238 | 247 | } |
239 | 248 | |
240 | 249 | //String must be normalized here |
241 | - if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) { |
|
250 | + if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) |
|
251 | + { |
|
242 | 252 | $result[$key] = $this->slugify->slugify($parameter); |
243 | 253 | continue; |
244 | 254 | } |
@@ -259,15 +269,20 @@ discard block |
||
259 | 269 | { |
260 | 270 | $path = $uri->getPath(); |
261 | 271 | |
262 | - if (empty($path) || $path[0] !== '/') { |
|
272 | + if (empty($path) || $path[0] !== '/') |
|
273 | + { |
|
263 | 274 | $path = '/' . $path; |
264 | 275 | } |
265 | 276 | |
266 | - if ($this->matchHost) { |
|
277 | + if ($this->matchHost) |
|
278 | + { |
|
267 | 279 | $uriString = $uri->getHost() . $path; |
268 | - } else { |
|
280 | + } |
|
281 | + else |
|
282 | + { |
|
269 | 283 | $uriString = substr($path, strlen($this->prefix)); |
270 | - if ($uriString === false) { |
|
284 | + if ($uriString === false) |
|
285 | + { |
|
271 | 286 | $uriString = ''; |
272 | 287 | } |
273 | 288 | } |
@@ -280,7 +295,8 @@ discard block |
||
280 | 295 | */ |
281 | 296 | private function compile(): void |
282 | 297 | { |
283 | - if ($this->pattern === null) { |
|
298 | + if ($this->pattern === null) |
|
299 | + { |
|
284 | 300 | throw new UriHandlerException('Unable to compile UriHandler, pattern is not set'); |
285 | 301 | } |
286 | 302 | |
@@ -288,14 +304,17 @@ discard block |
||
288 | 304 | $pattern = rtrim(ltrim($this->pattern, ':/'), '/'); |
289 | 305 | |
290 | 306 | // correct [/ first occurrence] |
291 | - if (strpos($pattern, '[/') === 0) { |
|
307 | + if (strpos($pattern, '[/') === 0) |
|
308 | + { |
|
292 | 309 | $pattern = '[' . substr($pattern, 2); |
293 | 310 | } |
294 | 311 | |
295 | - if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) { |
|
312 | + if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) |
|
313 | + { |
|
296 | 314 | $variables = array_combine($matches[1], $matches[2]); |
297 | 315 | |
298 | - foreach ($variables as $key => $segment) { |
|
316 | + foreach ($variables as $key => $segment) |
|
317 | + { |
|
299 | 318 | $segment = $this->prepareSegment($key, $segment); |
300 | 319 | $replaces["<$key>"] = "(?P<$key>$segment)"; |
301 | 320 | $options[] = $key; |
@@ -305,13 +324,16 @@ discard block |
||
305 | 324 | $template = preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern); |
306 | 325 | $options = array_fill_keys($options, null); |
307 | 326 | |
308 | - foreach ($this->constrains as $key => $value) { |
|
309 | - if ($value instanceof Autofill) { |
|
327 | + foreach ($this->constrains as $key => $value) |
|
328 | + { |
|
329 | + if ($value instanceof Autofill) |
|
330 | + { |
|
310 | 331 | // only forces value replacement, not required to be presented as parameter |
311 | 332 | continue; |
312 | 333 | } |
313 | 334 | |
314 | - if (!array_key_exists($key, $options) && !isset($this->defaults[$key])) { |
|
335 | + if (!array_key_exists($key, $options) && !isset($this->defaults[$key])) |
|
336 | + { |
|
315 | 337 | throw new ConstrainException( |
316 | 338 | sprintf( |
317 | 339 | 'Route `%s` does not define routing parameter `<%s>`.', |
@@ -337,7 +359,8 @@ discard block |
||
337 | 359 | private function interpolate(string $string, array $values): string |
338 | 360 | { |
339 | 361 | $replaces = []; |
340 | - foreach ($values as $key => $value) { |
|
362 | + foreach ($values as $key => $value) |
|
363 | + { |
|
341 | 364 | $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; |
342 | 365 | $replaces["<{$key}>"] = is_object($value) ? (string)$value : $value; |
343 | 366 | } |
@@ -354,15 +377,18 @@ discard block |
||
354 | 377 | */ |
355 | 378 | private function prepareSegment(string $name, string $segment): string |
356 | 379 | { |
357 | - if ($segment !== '') { |
|
380 | + if ($segment !== '') |
|
381 | + { |
|
358 | 382 | return self::SEGMENT_TYPES[$segment] ?? $segment; |
359 | 383 | } |
360 | 384 | |
361 | - if (!isset($this->constrains[$name])) { |
|
385 | + if (!isset($this->constrains[$name])) |
|
386 | + { |
|
362 | 387 | return self::DEFAULT_SEGMENT; |
363 | 388 | } |
364 | 389 | |
365 | - if (is_array($this->constrains[$name])) { |
|
390 | + if (is_array($this->constrains[$name])) |
|
391 | + { |
|
366 | 392 | $values = array_map([$this, 'filterSegment'], $this->constrains[$name]); |
367 | 393 | |
368 | 394 | return implode('|', $values); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | 'integer' => '\d+', |
33 | 33 | 'uuid' => '[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}', |
34 | 34 | ]; |
35 | - private const URI_FIXERS = [ |
|
35 | + private const URI_FIXERS = [ |
|
36 | 36 | '[]' => '', |
37 | 37 | '[/]' => '', |
38 | 38 | '[' => '', |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public function __construct( |
79 | 79 | UriFactoryInterface $uriFactory, |
80 | 80 | SlugifyInterface $slugify = null |
81 | - ) { |
|
81 | + ){ |
|
82 | 82 | $this->uriFactory = $uriFactory; |
83 | 83 | $this->slugify = $slugify ?? new Slugify(); |
84 | 84 | } |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function match(UriInterface $uri, array $defaults): ?array |
169 | 169 | { |
170 | - if (!$this->isCompiled()) { |
|
170 | + if (!$this->isCompiled()){ |
|
171 | 171 | $this->compile(); |
172 | 172 | } |
173 | 173 | |
174 | 174 | $matches = []; |
175 | - if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) { |
|
175 | + if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)){ |
|
176 | 176 | return null; |
177 | 177 | } |
178 | 178 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function uri($parameters = [], array $defaults = []): UriInterface |
192 | 192 | { |
193 | - if (!$this->isCompiled()) { |
|
193 | + if (!$this->isCompiled()){ |
|
194 | 194 | $this->compile(); |
195 | 195 | } |
196 | 196 | |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | $this->fetchOptions($parameters, $query) |
201 | 201 | ); |
202 | 202 | |
203 | - foreach ($this->constrains as $key => $_) { |
|
204 | - if (empty($parameters[$key])) { |
|
203 | + foreach ($this->constrains as $key => $_){ |
|
204 | + if (empty($parameters[$key])){ |
|
205 | 205 | throw new UriHandlerException("Unable to generate Uri, parameter `{$key}` is missing"); |
206 | 206 | } |
207 | 207 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $path = $this->interpolate($this->template, $parameters); |
211 | 211 | |
212 | 212 | //Uri with added prefix |
213 | - $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->prefix) . trim($path, '/')); |
|
213 | + $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->prefix).trim($path, '/')); |
|
214 | 214 | |
215 | 215 | return empty($query) ? $uri : $uri->withQuery(http_build_query($query)); |
216 | 216 | } |
@@ -227,18 +227,18 @@ discard block |
||
227 | 227 | $allowed = array_keys($this->options); |
228 | 228 | |
229 | 229 | $result = []; |
230 | - foreach ($parameters as $key => $parameter) { |
|
231 | - if (is_numeric($key) && isset($allowed[$key])) { |
|
230 | + foreach ($parameters as $key => $parameter){ |
|
231 | + if (is_numeric($key) && isset($allowed[$key])){ |
|
232 | 232 | // this segment fetched keys from given parameters either by name or by position |
233 | 233 | $key = $allowed[$key]; |
234 | - } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) { |
|
234 | + } elseif (!array_key_exists($key, $this->options) && is_array($parameters)){ |
|
235 | 235 | // all additional parameters given in array form can be glued to query string |
236 | 236 | $query[$key] = $parameter; |
237 | 237 | continue; |
238 | 238 | } |
239 | 239 | |
240 | 240 | //String must be normalized here |
241 | - if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) { |
|
241 | + if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)){ |
|
242 | 242 | $result[$key] = $this->slugify->slugify($parameter); |
243 | 243 | continue; |
244 | 244 | } |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | { |
260 | 260 | $path = $uri->getPath(); |
261 | 261 | |
262 | - if (empty($path) || $path[0] !== '/') { |
|
263 | - $path = '/' . $path; |
|
262 | + if (empty($path) || $path[0] !== '/'){ |
|
263 | + $path = '/'.$path; |
|
264 | 264 | } |
265 | 265 | |
266 | - if ($this->matchHost) { |
|
267 | - $uriString = $uri->getHost() . $path; |
|
268 | - } else { |
|
266 | + if ($this->matchHost){ |
|
267 | + $uriString = $uri->getHost().$path; |
|
268 | + }else{ |
|
269 | 269 | $uriString = substr($path, strlen($this->prefix)); |
270 | - if ($uriString === false) { |
|
270 | + if ($uriString === false){ |
|
271 | 271 | $uriString = ''; |
272 | 272 | } |
273 | 273 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | */ |
281 | 281 | private function compile(): void |
282 | 282 | { |
283 | - if ($this->pattern === null) { |
|
283 | + if ($this->pattern === null){ |
|
284 | 284 | throw new UriHandlerException('Unable to compile UriHandler, pattern is not set'); |
285 | 285 | } |
286 | 286 | |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | $pattern = rtrim(ltrim($this->pattern, ':/'), '/'); |
289 | 289 | |
290 | 290 | // correct [/ first occurrence] |
291 | - if (strpos($pattern, '[/') === 0) { |
|
292 | - $pattern = '[' . substr($pattern, 2); |
|
291 | + if (strpos($pattern, '[/') === 0){ |
|
292 | + $pattern = '['.substr($pattern, 2); |
|
293 | 293 | } |
294 | 294 | |
295 | - if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) { |
|
295 | + if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)){ |
|
296 | 296 | $variables = array_combine($matches[1], $matches[2]); |
297 | 297 | |
298 | - foreach ($variables as $key => $segment) { |
|
298 | + foreach ($variables as $key => $segment){ |
|
299 | 299 | $segment = $this->prepareSegment($key, $segment); |
300 | 300 | $replaces["<$key>"] = "(?P<$key>$segment)"; |
301 | 301 | $options[] = $key; |
@@ -305,13 +305,13 @@ discard block |
||
305 | 305 | $template = preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern); |
306 | 306 | $options = array_fill_keys($options, null); |
307 | 307 | |
308 | - foreach ($this->constrains as $key => $value) { |
|
309 | - if ($value instanceof Autofill) { |
|
308 | + foreach ($this->constrains as $key => $value){ |
|
309 | + if ($value instanceof Autofill){ |
|
310 | 310 | // only forces value replacement, not required to be presented as parameter |
311 | 311 | continue; |
312 | 312 | } |
313 | 313 | |
314 | - if (!array_key_exists($key, $options) && !isset($this->defaults[$key])) { |
|
314 | + if (!array_key_exists($key, $options) && !isset($this->defaults[$key])){ |
|
315 | 315 | throw new ConstrainException( |
316 | 316 | sprintf( |
317 | 317 | 'Route `%s` does not define routing parameter `<%s>`.', |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | - $this->compiled = '/^' . strtr($template, $replaces + self::PATTERN_REPLACES) . '$/iu'; |
|
325 | + $this->compiled = '/^'.strtr($template, $replaces + self::PATTERN_REPLACES).'$/iu'; |
|
326 | 326 | $this->template = stripslashes(str_replace('?', '', $template)); |
327 | 327 | $this->options = $options; |
328 | 328 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | private function interpolate(string $string, array $values): string |
338 | 338 | { |
339 | 339 | $replaces = []; |
340 | - foreach ($values as $key => $value) { |
|
340 | + foreach ($values as $key => $value){ |
|
341 | 341 | $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; |
342 | 342 | $replaces["<{$key}>"] = is_object($value) ? (string)$value : $value; |
343 | 343 | } |
@@ -354,15 +354,15 @@ discard block |
||
354 | 354 | */ |
355 | 355 | private function prepareSegment(string $name, string $segment): string |
356 | 356 | { |
357 | - if ($segment !== '') { |
|
357 | + if ($segment !== ''){ |
|
358 | 358 | return self::SEGMENT_TYPES[$segment] ?? $segment; |
359 | 359 | } |
360 | 360 | |
361 | - if (!isset($this->constrains[$name])) { |
|
361 | + if (!isset($this->constrains[$name])){ |
|
362 | 362 | return self::DEFAULT_SEGMENT; |
363 | 363 | } |
364 | 364 | |
365 | - if (is_array($this->constrains[$name])) { |
|
365 | + if (is_array($this->constrains[$name])){ |
|
366 | 366 | $values = array_map([$this, 'filterSegment'], $this->constrains[$name]); |
367 | 367 | |
368 | 368 | return implode('|', $values); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function apply($element, string $type, string $context = ''): string |
118 | 118 | { |
119 | - if (!empty($style = $this->getStyle($type, $context))) { |
|
119 | + if (!empty($style = $this->getStyle($type, $context))){ |
|
120 | 120 | return sprintf($this->style['element'], $style, $element); |
121 | 121 | } |
122 | 122 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function indent(int $level): string |
138 | 138 | { |
139 | - if ($level == 0) { |
|
139 | + if ($level == 0){ |
|
140 | 140 | return ''; |
141 | 141 | } |
142 | 142 | |
@@ -161,15 +161,15 @@ discard block |
||
161 | 161 | */ |
162 | 162 | private function getStyle(string $type, string $context): string |
163 | 163 | { |
164 | - if (isset($this->style[$type][$context])) { |
|
164 | + if (isset($this->style[$type][$context])){ |
|
165 | 165 | return $this->style[$type][$context]; |
166 | 166 | } |
167 | 167 | |
168 | - if (isset($this->style[$type]['common'])) { |
|
168 | + if (isset($this->style[$type]['common'])){ |
|
169 | 169 | return $this->style[$type]['common']; |
170 | 170 | } |
171 | 171 | |
172 | - if (isset($this->style[$type]) && is_string($this->style[$type])) { |
|
172 | + if (isset($this->style[$type]) && is_string($this->style[$type])){ |
|
173 | 173 | return $this->style[$type]; |
174 | 174 | } |
175 | 175 |
@@ -116,7 +116,8 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function apply($element, string $type, string $context = ''): string |
118 | 118 | { |
119 | - if (!empty($style = $this->getStyle($type, $context))) { |
|
119 | + if (!empty($style = $this->getStyle($type, $context))) |
|
120 | + { |
|
120 | 121 | return sprintf($this->style['element'], $style, $element); |
121 | 122 | } |
122 | 123 | |
@@ -136,7 +137,8 @@ discard block |
||
136 | 137 | */ |
137 | 138 | public function indent(int $level): string |
138 | 139 | { |
139 | - if ($level == 0) { |
|
140 | + if ($level == 0) |
|
141 | + { |
|
140 | 142 | return ''; |
141 | 143 | } |
142 | 144 | |
@@ -161,15 +163,18 @@ discard block |
||
161 | 163 | */ |
162 | 164 | private function getStyle(string $type, string $context): string |
163 | 165 | { |
164 | - if (isset($this->style[$type][$context])) { |
|
166 | + if (isset($this->style[$type][$context])) |
|
167 | + { |
|
165 | 168 | return $this->style[$type][$context]; |
166 | 169 | } |
167 | 170 | |
168 | - if (isset($this->style[$type]['common'])) { |
|
171 | + if (isset($this->style[$type]['common'])) |
|
172 | + { |
|
169 | 173 | return $this->style[$type]['common']; |
170 | 174 | } |
171 | 175 | |
172 | - if (isset($this->style[$type]) && is_string($this->style[$type])) { |
|
176 | + if (isset($this->style[$type]) && is_string($this->style[$type])) |
|
177 | + { |
|
173 | 178 | return $this->style[$type]; |
174 | 179 | } |
175 | 180 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Default coloring schema. |
23 | 23 | */ |
24 | - public const DEFAULT = [ |
|
24 | + public const default = [ |
|
25 | 25 | 'body' => '<pre style="background-color: white; font-family: monospace;">%s</pre>', |
26 | 26 | 'element' => '<span style="%s;">%s</span>', |
27 | 27 | 'indent' => '· ', |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @var array |
103 | 103 | */ |
104 | - protected $style = self::DEFAULT; |
|
104 | + protected $style = self::default; |
|
105 | 105 | |
106 | - public function __construct(array $style = self::DEFAULT) |
|
106 | + public function __construct(array $style = self::default) |
|
107 | 107 | { |
108 | 108 | $this->style = $style; |
109 | 109 | } |
@@ -43,16 +43,16 @@ |
||
43 | 43 | if ( |
44 | 44 | !$node instanceof PHP |
45 | 45 | || strpos($node->content, self::PHP_MARCO_EXISTS_FUNCTION) === false |
46 | - ) { |
|
46 | + ){ |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if ($node->getContext()->getPath() !== $this->path) { |
|
50 | + if ($node->getContext()->getPath() !== $this->path){ |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
55 | - foreach ($exists->getBlocks() as $name => $_) { |
|
55 | + foreach ($exists->getBlocks() as $name => $_){ |
|
56 | 56 | // do not leak to parent template |
57 | 57 | $exists->set($name, 'false'); |
58 | 58 | } |
@@ -47,12 +47,14 @@ |
||
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if ($node->getContext()->getPath() !== $this->path) { |
|
50 | + if ($node->getContext()->getPath() !== $this->path) |
|
51 | + { |
|
51 | 52 | return; |
52 | 53 | } |
53 | 54 | |
54 | 55 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
55 | - foreach ($exists->getBlocks() as $name => $_) { |
|
56 | + foreach ($exists->getBlocks() as $name => $_) |
|
57 | + { |
|
56 | 58 | // do not leak to parent template |
57 | 59 | $exists->set($name, 'false'); |
58 | 60 | } |
@@ -46,24 +46,24 @@ discard block |
||
46 | 46 | public function trimValue(): array |
47 | 47 | { |
48 | 48 | $value = $this->value; |
49 | - if ($value instanceof Nil) { |
|
49 | + if ($value instanceof Nil){ |
|
50 | 50 | return []; |
51 | 51 | } |
52 | 52 | |
53 | - if (is_string($value)) { |
|
53 | + if (is_string($value)){ |
|
54 | 54 | return [new Raw(trim($value, '\'"'))]; |
55 | 55 | } |
56 | 56 | |
57 | - if (!$value instanceof Mixin) { |
|
57 | + if (!$value instanceof Mixin){ |
|
58 | 58 | return [$value]; |
59 | 59 | } |
60 | 60 | |
61 | 61 | // trim mixin quotes |
62 | 62 | $nodes = $value->nodes; |
63 | 63 | |
64 | - if (count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[count($nodes) - 1] instanceof Raw) { |
|
64 | + if (count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[count($nodes) - 1] instanceof Raw){ |
|
65 | 65 | $quote = $nodes[0]->content[0]; |
66 | - if (!in_array($quote, ['"', '\''])) { |
|
66 | + if (!in_array($quote, ['"', '\''])){ |
|
67 | 67 | return $nodes; |
68 | 68 | } |
69 | 69 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | ); |
74 | 74 | } |
75 | 75 | |
76 | - foreach ($nodes as $index => $node) { |
|
77 | - if ($node instanceof Raw && $node->content === '') { |
|
76 | + foreach ($nodes as $index => $node){ |
|
77 | + if ($node instanceof Raw && $node->content === ''){ |
|
78 | 78 | unset($nodes[$index]); |
79 | 79 | } |
80 | 80 | } |
@@ -46,24 +46,29 @@ discard block |
||
46 | 46 | public function trimValue(): array |
47 | 47 | { |
48 | 48 | $value = $this->value; |
49 | - if ($value instanceof Nil) { |
|
49 | + if ($value instanceof Nil) |
|
50 | + { |
|
50 | 51 | return []; |
51 | 52 | } |
52 | 53 | |
53 | - if (is_string($value)) { |
|
54 | + if (is_string($value)) |
|
55 | + { |
|
54 | 56 | return [new Raw(trim($value, '\'"'))]; |
55 | 57 | } |
56 | 58 | |
57 | - if (!$value instanceof Mixin) { |
|
59 | + if (!$value instanceof Mixin) |
|
60 | + { |
|
58 | 61 | return [$value]; |
59 | 62 | } |
60 | 63 | |
61 | 64 | // trim mixin quotes |
62 | 65 | $nodes = $value->nodes; |
63 | 66 | |
64 | - if (count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[count($nodes) - 1] instanceof Raw) { |
|
67 | + if (count($nodes) >= 3 && $nodes[0] instanceof Raw && $nodes[count($nodes) - 1] instanceof Raw) |
|
68 | + { |
|
65 | 69 | $quote = $nodes[0]->content[0]; |
66 | - if (!in_array($quote, ['"', '\''])) { |
|
70 | + if (!in_array($quote, ['"', '\''])) |
|
71 | + { |
|
67 | 72 | return $nodes; |
68 | 73 | } |
69 | 74 | |
@@ -73,8 +78,10 @@ discard block |
||
73 | 78 | ); |
74 | 79 | } |
75 | 80 | |
76 | - foreach ($nodes as $index => $node) { |
|
77 | - if ($node instanceof Raw && $node->content === '') { |
|
81 | + foreach ($nodes as $index => $node) |
|
82 | + { |
|
83 | + if ($node instanceof Raw && $node->content === '') |
|
84 | + { |
|
78 | 85 | unset($nodes[$index]); |
79 | 86 | } |
80 | 87 | } |
@@ -46,17 +46,17 @@ discard block |
||
46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
47 | 47 | |
48 | 48 | $contextCandidates = []; |
49 | - foreach ($entities as $parameter => $role) { |
|
49 | + foreach ($entities as $parameter => $role){ |
|
50 | 50 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
51 | - if ($value === null) { |
|
51 | + if ($value === null){ |
|
52 | 52 | throw new ControllerException( |
53 | 53 | "Entity `{$parameter}` can not be found", |
54 | 54 | ControllerException::NOT_FOUND |
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
58 | - if (is_object($value)) { |
|
59 | - if ($this->orm->getHeap()->has($value)) { |
|
58 | + if (is_object($value)){ |
|
59 | + if ($this->orm->getHeap()->has($value)){ |
|
60 | 60 | $contextCandidates[] = $value; |
61 | 61 | } |
62 | 62 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | $entity = $this->resolveEntity($role, $value); |
68 | - if ($entity === null) { |
|
68 | + if ($entity === null){ |
|
69 | 69 | throw new ControllerException( |
70 | 70 | "Entity `{$parameter}` can not be found", |
71 | 71 | ControllerException::NOT_FOUND |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $contextCandidates[] = $entity; |
77 | 77 | } |
78 | 78 | |
79 | - if (!isset($parameters['@context']) && count($contextCandidates) === 1) { |
|
79 | + if (!isset($parameters['@context']) && count($contextCandidates) === 1){ |
|
80 | 80 | $parameters['@context'] = current($contextCandidates); |
81 | 81 | } |
82 | 82 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
93 | 93 | { |
94 | - if (!$useDefault) { |
|
94 | + if (!$useDefault){ |
|
95 | 95 | return $parameters[$role] ?? null; |
96 | 96 | } |
97 | 97 | |
@@ -116,25 +116,25 @@ discard block |
||
116 | 116 | private function getDeclaredEntities(string $controller, string $action): array |
117 | 117 | { |
118 | 118 | $key = sprintf('%s:%s', $controller, $action); |
119 | - if (array_key_exists($key, $this->cache)) { |
|
119 | + if (array_key_exists($key, $this->cache)){ |
|
120 | 120 | return $this->cache[$key]; |
121 | 121 | } |
122 | 122 | |
123 | 123 | $this->cache[$key] = []; |
124 | - try { |
|
124 | + try{ |
|
125 | 125 | $method = new \ReflectionMethod($controller, $action); |
126 | - } catch (\ReflectionException $e) { |
|
126 | + }catch (\ReflectionException $e){ |
|
127 | 127 | return []; |
128 | 128 | } |
129 | 129 | |
130 | - foreach ($method->getParameters() as $parameter) { |
|
130 | + foreach ($method->getParameters() as $parameter){ |
|
131 | 131 | $class = $this->getParameterClass($parameter); |
132 | 132 | |
133 | - if ($class === null) { |
|
133 | + if ($class === null){ |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | |
137 | - if ($this->orm->getSchema()->defines($class->getName())) { |
|
137 | + if ($this->orm->getSchema()->defines($class->getName())){ |
|
138 | 138 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($class->getName()); |
139 | 139 | } |
140 | 140 | } |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | { |
151 | 151 | $type = $parameter->getType(); |
152 | 152 | |
153 | - if (!$type instanceof \ReflectionNamedType) { |
|
153 | + if (!$type instanceof \ReflectionNamedType){ |
|
154 | 154 | return null; |
155 | 155 | } |
156 | 156 | |
157 | - if ($type->isBuiltin()) { |
|
157 | + if ($type->isBuiltin()){ |
|
158 | 158 | return null; |
159 | 159 | } |
160 | 160 |
@@ -46,17 +46,21 @@ discard block |
||
46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
47 | 47 | |
48 | 48 | $contextCandidates = []; |
49 | - foreach ($entities as $parameter => $role) { |
|
49 | + foreach ($entities as $parameter => $role) |
|
50 | + { |
|
50 | 51 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
51 | - if ($value === null) { |
|
52 | + if ($value === null) |
|
53 | + { |
|
52 | 54 | throw new ControllerException( |
53 | 55 | "Entity `{$parameter}` can not be found", |
54 | 56 | ControllerException::NOT_FOUND |
55 | 57 | ); |
56 | 58 | } |
57 | 59 | |
58 | - if (is_object($value)) { |
|
59 | - if ($this->orm->getHeap()->has($value)) { |
|
60 | + if (is_object($value)) |
|
61 | + { |
|
62 | + if ($this->orm->getHeap()->has($value)) |
|
63 | + { |
|
60 | 64 | $contextCandidates[] = $value; |
61 | 65 | } |
62 | 66 | |
@@ -65,7 +69,8 @@ discard block |
||
65 | 69 | } |
66 | 70 | |
67 | 71 | $entity = $this->resolveEntity($role, $value); |
68 | - if ($entity === null) { |
|
72 | + if ($entity === null) |
|
73 | + { |
|
69 | 74 | throw new ControllerException( |
70 | 75 | "Entity `{$parameter}` can not be found", |
71 | 76 | ControllerException::NOT_FOUND |
@@ -76,7 +81,8 @@ discard block |
||
76 | 81 | $contextCandidates[] = $entity; |
77 | 82 | } |
78 | 83 | |
79 | - if (!isset($parameters['@context']) && count($contextCandidates) === 1) { |
|
84 | + if (!isset($parameters['@context']) && count($contextCandidates) === 1) |
|
85 | + { |
|
80 | 86 | $parameters['@context'] = current($contextCandidates); |
81 | 87 | } |
82 | 88 | |
@@ -91,7 +97,8 @@ discard block |
||
91 | 97 | */ |
92 | 98 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
93 | 99 | { |
94 | - if (!$useDefault) { |
|
100 | + if (!$useDefault) |
|
101 | + { |
|
95 | 102 | return $parameters[$role] ?? null; |
96 | 103 | } |
97 | 104 | |
@@ -116,25 +123,32 @@ discard block |
||
116 | 123 | private function getDeclaredEntities(string $controller, string $action): array |
117 | 124 | { |
118 | 125 | $key = sprintf('%s:%s', $controller, $action); |
119 | - if (array_key_exists($key, $this->cache)) { |
|
126 | + if (array_key_exists($key, $this->cache)) |
|
127 | + { |
|
120 | 128 | return $this->cache[$key]; |
121 | 129 | } |
122 | 130 | |
123 | 131 | $this->cache[$key] = []; |
124 | - try { |
|
132 | + try |
|
133 | + { |
|
125 | 134 | $method = new \ReflectionMethod($controller, $action); |
126 | - } catch (\ReflectionException $e) { |
|
135 | + } |
|
136 | + catch (\ReflectionException $e) |
|
137 | + { |
|
127 | 138 | return []; |
128 | 139 | } |
129 | 140 | |
130 | - foreach ($method->getParameters() as $parameter) { |
|
141 | + foreach ($method->getParameters() as $parameter) |
|
142 | + { |
|
131 | 143 | $class = $this->getParameterClass($parameter); |
132 | 144 | |
133 | - if ($class === null) { |
|
145 | + if ($class === null) |
|
146 | + { |
|
134 | 147 | continue; |
135 | 148 | } |
136 | 149 | |
137 | - if ($this->orm->getSchema()->defines($class->getName())) { |
|
150 | + if ($this->orm->getSchema()->defines($class->getName())) |
|
151 | + { |
|
138 | 152 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($class->getName()); |
139 | 153 | } |
140 | 154 | } |
@@ -150,11 +164,13 @@ discard block |
||
150 | 164 | { |
151 | 165 | $type = $parameter->getType(); |
152 | 166 | |
153 | - if (!$type instanceof \ReflectionNamedType) { |
|
167 | + if (!$type instanceof \ReflectionNamedType) |
|
168 | + { |
|
154 | 169 | return null; |
155 | 170 | } |
156 | 171 | |
157 | - if ($type->isBuiltin()) { |
|
172 | + if ($type->isBuiltin()) |
|
173 | + { |
|
158 | 174 | return null; |
159 | 175 | } |
160 | 176 |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | FilesInterface $files, |
53 | 53 | DirectoriesInterface $directories |
54 | 54 | ): void { |
55 | - switch ($this->argument('type')) { |
|
55 | + switch ($this->argument('type')){ |
|
56 | 56 | case 'replace': |
57 | 57 | case 'follow': |
58 | - if ($this->isDirectory()) { |
|
58 | + if ($this->isDirectory()){ |
|
59 | 59 | $this->sprintf( |
60 | 60 | '<fg=cyan>•</fg=cyan> publish directory <comment>%s</comment> to <comment>%s</comment>', |
61 | 61 | $this->getSource($files), |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $this->getMergeMode(), |
69 | 69 | $this->getFileMode() |
70 | 70 | ); |
71 | - } else { |
|
71 | + }else{ |
|
72 | 72 | $this->sprintf( |
73 | 73 | '<fg=cyan>•</fg=cyan> publish file <comment>%s</comment> to <comment>%s</comment>', |
74 | 74 | $this->getSource($files), |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | private function getSource(FilesInterface $files): ?string |
109 | 109 | { |
110 | - if (!$this->isDirectory()) { |
|
110 | + if (!$this->isDirectory()){ |
|
111 | 111 | return $files->normalizePath($this->argument('source')); |
112 | 112 | } |
113 | 113 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | private function getTarget(FilesInterface $files, DirectoriesInterface $directories): ?string |
123 | 123 | { |
124 | 124 | $target = $this->argument('target'); |
125 | - foreach ($directories->getAll() as $alias => $value) { |
|
125 | + foreach ($directories->getAll() as $alias => $value){ |
|
126 | 126 | $target = str_replace("@{$alias}", $value, $target); |
127 | 127 | } |
128 | 128 | |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | */ |
135 | 135 | private function isDirectory(): bool |
136 | 136 | { |
137 | - if ($this->argument('type') == 'ensure') { |
|
137 | + if ($this->argument('type') == 'ensure'){ |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | |
141 | - if (strpos($this->argument('source'), '*') !== false) { |
|
141 | + if (strpos($this->argument('source'), '*') !== false){ |
|
142 | 142 | return true; |
143 | 143 | } |
144 | 144 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | private function getMergeMode(): string |
152 | 152 | { |
153 | - switch ($this->argument('type')) { |
|
153 | + switch ($this->argument('type')){ |
|
154 | 154 | case 'follow': |
155 | 155 | return PublisherInterface::FOLLOW; |
156 | 156 | case 'replace': |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | private function getFileMode(): int |
167 | 167 | { |
168 | - switch ($this->argument('mode')) { |
|
168 | + switch ($this->argument('mode')){ |
|
169 | 169 | case 'readonly': |
170 | 170 | return FilesInterface::READONLY; |
171 | 171 | case 'runtime': |
@@ -52,10 +52,12 @@ discard block |
||
52 | 52 | FilesInterface $files, |
53 | 53 | DirectoriesInterface $directories |
54 | 54 | ): void { |
55 | - switch ($this->argument('type')) { |
|
55 | + switch ($this->argument('type')) |
|
56 | + { |
|
56 | 57 | case 'replace': |
57 | 58 | case 'follow': |
58 | - if ($this->isDirectory()) { |
|
59 | + if ($this->isDirectory()) |
|
60 | + { |
|
59 | 61 | $this->sprintf( |
60 | 62 | '<fg=cyan>•</fg=cyan> publish directory <comment>%s</comment> to <comment>%s</comment>', |
61 | 63 | $this->getSource($files), |
@@ -68,7 +70,9 @@ discard block |
||
68 | 70 | $this->getMergeMode(), |
69 | 71 | $this->getFileMode() |
70 | 72 | ); |
71 | - } else { |
|
73 | + } |
|
74 | + else |
|
75 | + { |
|
72 | 76 | $this->sprintf( |
73 | 77 | '<fg=cyan>•</fg=cyan> publish file <comment>%s</comment> to <comment>%s</comment>', |
74 | 78 | $this->getSource($files), |
@@ -107,7 +111,8 @@ discard block |
||
107 | 111 | */ |
108 | 112 | private function getSource(FilesInterface $files): ?string |
109 | 113 | { |
110 | - if (!$this->isDirectory()) { |
|
114 | + if (!$this->isDirectory()) |
|
115 | + { |
|
111 | 116 | return $files->normalizePath($this->argument('source')); |
112 | 117 | } |
113 | 118 | |
@@ -122,7 +127,8 @@ discard block |
||
122 | 127 | private function getTarget(FilesInterface $files, DirectoriesInterface $directories): ?string |
123 | 128 | { |
124 | 129 | $target = $this->argument('target'); |
125 | - foreach ($directories->getAll() as $alias => $value) { |
|
130 | + foreach ($directories->getAll() as $alias => $value) |
|
131 | + { |
|
126 | 132 | $target = str_replace("@{$alias}", $value, $target); |
127 | 133 | } |
128 | 134 | |
@@ -134,11 +140,13 @@ discard block |
||
134 | 140 | */ |
135 | 141 | private function isDirectory(): bool |
136 | 142 | { |
137 | - if ($this->argument('type') == 'ensure') { |
|
143 | + if ($this->argument('type') == 'ensure') |
|
144 | + { |
|
138 | 145 | return true; |
139 | 146 | } |
140 | 147 | |
141 | - if (strpos($this->argument('source'), '*') !== false) { |
|
148 | + if (strpos($this->argument('source'), '*') !== false) |
|
149 | + { |
|
142 | 150 | return true; |
143 | 151 | } |
144 | 152 | |
@@ -150,7 +158,8 @@ discard block |
||
150 | 158 | */ |
151 | 159 | private function getMergeMode(): string |
152 | 160 | { |
153 | - switch ($this->argument('type')) { |
|
161 | + switch ($this->argument('type')) |
|
162 | + { |
|
154 | 163 | case 'follow': |
155 | 164 | return PublisherInterface::FOLLOW; |
156 | 165 | case 'replace': |
@@ -165,7 +174,8 @@ discard block |
||
165 | 174 | */ |
166 | 175 | private function getFileMode(): int |
167 | 176 | { |
168 | - switch ($this->argument('mode')) { |
|
177 | + switch ($this->argument('mode')) |
|
178 | + { |
|
169 | 179 | case 'readonly': |
170 | 180 | return FilesInterface::READONLY; |
171 | 181 | case 'runtime': |
@@ -167,7 +167,7 @@ |
||
167 | 167 | { |
168 | 168 | switch ($this->argument('mode')) { |
169 | 169 | case 'readonly': |
170 | - return FilesInterface::READONLY; |
|
170 | + return FilesInterface::readonly; |
|
171 | 171 | case 'runtime': |
172 | 172 | return FilesInterface::RUNTIME; |
173 | 173 | default: |
@@ -41,17 +41,17 @@ discard block |
||
41 | 41 | string $mergeMode = self::FOLLOW, |
42 | 42 | int $mode = FilesInterface::READONLY |
43 | 43 | ): void { |
44 | - if (!$this->files->isFile($filename)) { |
|
44 | + if (!$this->files->isFile($filename)){ |
|
45 | 45 | throw new PublishException("Given '{$filename}' is not valid file"); |
46 | 46 | } |
47 | 47 | |
48 | - if ($this->files->exists($destination)) { |
|
49 | - if ($this->files->md5($destination) === $this->files->md5($filename)) { |
|
48 | + if ($this->files->exists($destination)){ |
|
49 | + if ($this->files->md5($destination) === $this->files->md5($filename)){ |
|
50 | 50 | //Nothing to do |
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | - if ($mergeMode === self::FOLLOW) { |
|
54 | + if ($mergeMode === self::FOLLOW){ |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | } |
@@ -73,17 +73,17 @@ discard block |
||
73 | 73 | string $mergeMode = self::REPLACE, |
74 | 74 | int $mode = FilesInterface::READONLY |
75 | 75 | ): void { |
76 | - if (!$this->files->isDirectory($directory)) { |
|
76 | + if (!$this->files->isDirectory($directory)){ |
|
77 | 77 | throw new PublishException("Given '{$directory}' is not valid directory"); |
78 | 78 | } |
79 | 79 | |
80 | 80 | $finder = new Finder(); |
81 | 81 | $finder->files()->in($directory); |
82 | 82 | |
83 | - foreach ($finder->getIterator() as $file) { |
|
83 | + foreach ($finder->getIterator() as $file){ |
|
84 | 84 | $this->publish( |
85 | 85 | (string)$file, |
86 | - $destination . '/' . $file->getRelativePathname(), |
|
86 | + $destination.'/'.$file->getRelativePathname(), |
|
87 | 87 | $mergeMode, |
88 | 88 | $mode |
89 | 89 | ); |
@@ -41,17 +41,21 @@ discard block |
||
41 | 41 | string $mergeMode = self::FOLLOW, |
42 | 42 | int $mode = FilesInterface::READONLY |
43 | 43 | ): void { |
44 | - if (!$this->files->isFile($filename)) { |
|
44 | + if (!$this->files->isFile($filename)) |
|
45 | + { |
|
45 | 46 | throw new PublishException("Given '{$filename}' is not valid file"); |
46 | 47 | } |
47 | 48 | |
48 | - if ($this->files->exists($destination)) { |
|
49 | - if ($this->files->md5($destination) === $this->files->md5($filename)) { |
|
49 | + if ($this->files->exists($destination)) |
|
50 | + { |
|
51 | + if ($this->files->md5($destination) === $this->files->md5($filename)) |
|
52 | + { |
|
50 | 53 | //Nothing to do |
51 | 54 | return; |
52 | 55 | } |
53 | 56 | |
54 | - if ($mergeMode === self::FOLLOW) { |
|
57 | + if ($mergeMode === self::FOLLOW) |
|
58 | + { |
|
55 | 59 | return; |
56 | 60 | } |
57 | 61 | } |
@@ -73,14 +77,16 @@ discard block |
||
73 | 77 | string $mergeMode = self::REPLACE, |
74 | 78 | int $mode = FilesInterface::READONLY |
75 | 79 | ): void { |
76 | - if (!$this->files->isDirectory($directory)) { |
|
80 | + if (!$this->files->isDirectory($directory)) |
|
81 | + { |
|
77 | 82 | throw new PublishException("Given '{$directory}' is not valid directory"); |
78 | 83 | } |
79 | 84 | |
80 | 85 | $finder = new Finder(); |
81 | 86 | $finder->files()->in($directory); |
82 | 87 | |
83 | - foreach ($finder->getIterator() as $file) { |
|
88 | + foreach ($finder->getIterator() as $file) |
|
89 | + { |
|
84 | 90 | $this->publish( |
85 | 91 | (string)$file, |
86 | 92 | $destination . '/' . $file->getRelativePathname(), |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | string $filename, |
40 | 40 | string $destination, |
41 | 41 | string $mergeMode = self::FOLLOW, |
42 | - int $mode = FilesInterface::READONLY |
|
42 | + int $mode = FilesInterface::readonly |
|
43 | 43 | ): void { |
44 | 44 | if (!$this->files->isFile($filename)) { |
45 | 45 | throw new PublishException("Given '{$filename}' is not valid file"); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | string $directory, |
72 | 72 | string $destination, |
73 | 73 | string $mergeMode = self::REPLACE, |
74 | - int $mode = FilesInterface::READONLY |
|
74 | + int $mode = FilesInterface::readonly |
|
75 | 75 | ): void { |
76 | 76 | if (!$this->files->isDirectory($directory)) { |
77 | 77 | throw new PublishException("Given '{$directory}' is not valid directory"); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | /** |
94 | 94 | * {@inheritdoc} |
95 | 95 | */ |
96 | - public function ensureDirectory(string $directory, int $mode = FilesInterface::READONLY): void |
|
96 | + public function ensureDirectory(string $directory, int $mode = FilesInterface::readonly): void |
|
97 | 97 | { |
98 | 98 | $this->files->ensureDirectory($directory, $mode); |
99 | 99 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | { |
35 | 35 | parent::__construct($config); |
36 | 36 | |
37 | - foreach ($config['authorizeTopics'] as $topic => $callback) { |
|
37 | + foreach ($config['authorizeTopics'] as $topic => $callback){ |
|
38 | 38 | $this->patterns[$this->compilePattern($topic)] = $callback; |
39 | 39 | } |
40 | 40 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function findTopicCallback(string $topic, array &$matches): ?callable |
64 | 64 | { |
65 | - foreach ($this->patterns as $pattern => $callback) { |
|
66 | - if (preg_match($pattern, $topic, $matches)) { |
|
65 | + foreach ($this->patterns as $pattern => $callback){ |
|
66 | + if (preg_match($pattern, $topic, $matches)){ |
|
67 | 67 | return $callback; |
68 | 68 | } |
69 | 69 | } |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | private function compilePattern(string $topic): string |
79 | 79 | { |
80 | 80 | $replaces = []; |
81 | - if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)) { |
|
81 | + if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)){ |
|
82 | 82 | $variables = array_combine($matches[1], $matches[2]); |
83 | - foreach ($variables as $key => $_) { |
|
84 | - $replaces['{' . $key . '}'] = '(?P<' . $key . '>[^\/\.]+)'; |
|
83 | + foreach ($variables as $key => $_){ |
|
84 | + $replaces['{'.$key.'}'] = '(?P<'.$key.'>[^\/\.]+)'; |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - return '/^' . strtr($topic, $replaces + ['/' => '\\/', '[' => '(?:', ']' => ')?', '.' => '\.']) . '$/iu'; |
|
88 | + return '/^'.strtr($topic, $replaces + ['/' => '\\/', '[' => '(?:', ']' => ')?', '.' => '\.']).'$/iu'; |
|
89 | 89 | } |
90 | 90 | } |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | { |
35 | 35 | parent::__construct($config); |
36 | 36 | |
37 | - foreach ($config['authorizeTopics'] as $topic => $callback) { |
|
37 | + foreach ($config['authorizeTopics'] as $topic => $callback) |
|
38 | + { |
|
38 | 39 | $this->patterns[$this->compilePattern($topic)] = $callback; |
39 | 40 | } |
40 | 41 | } |
@@ -62,8 +63,10 @@ discard block |
||
62 | 63 | */ |
63 | 64 | public function findTopicCallback(string $topic, array &$matches): ?callable |
64 | 65 | { |
65 | - foreach ($this->patterns as $pattern => $callback) { |
|
66 | - if (preg_match($pattern, $topic, $matches)) { |
|
66 | + foreach ($this->patterns as $pattern => $callback) |
|
67 | + { |
|
68 | + if (preg_match($pattern, $topic, $matches)) |
|
69 | + { |
|
67 | 70 | return $callback; |
68 | 71 | } |
69 | 72 | } |
@@ -78,9 +81,11 @@ discard block |
||
78 | 81 | private function compilePattern(string $topic): string |
79 | 82 | { |
80 | 83 | $replaces = []; |
81 | - if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)) { |
|
84 | + if (preg_match_all('/\{(\w+):?(.*?)?\}/', $topic, $matches)) |
|
85 | + { |
|
82 | 86 | $variables = array_combine($matches[1], $matches[2]); |
83 | - foreach ($variables as $key => $_) { |
|
87 | + foreach ($variables as $key => $_) |
|
88 | + { |
|
84 | 89 | $replaces['{' . $key . '}'] = '(?P<' . $key . '>[^\/\.]+)'; |
85 | 90 | } |
86 | 91 | } |