Passed
Push — master ( d7c804...5e483c )
by butschster
09:23 queued 13s
created
src/Router/src/UriHandler.php 1 patch
Braces   +46 added lines, -22 removed lines patch added patch discarded remove patch
@@ -103,7 +103,8 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function withBasePath(string $basePath): self
105 105
     {
106
-        if (!\str_ends_with($basePath, '/')) {
106
+        if (!\str_ends_with($basePath, '/'))
107
+        {
107 108
             $basePath .= '/';
108 109
         }
109 110
 
@@ -153,12 +154,14 @@  discard block
 block discarded – undo
153 154
      */
154 155
     public function match(UriInterface $uri, array $defaults): ?array
155 156
     {
156
-        if (!$this->isCompiled()) {
157
+        if (!$this->isCompiled())
158
+        {
157 159
             $this->compile();
158 160
         }
159 161
 
160 162
         $matches = [];
161
-        if (!\preg_match($this->compiled, $this->fetchTarget($uri), $matches)) {
163
+        if (!\preg_match($this->compiled, $this->fetchTarget($uri), $matches))
164
+        {
162 165
             return null;
163 166
         }
164 167
 
@@ -175,7 +178,8 @@  discard block
 block discarded – undo
175 178
      */
176 179
     public function uri(iterable $parameters = [], array $defaults = []): UriInterface
177 180
     {
178
-        if (!$this->isCompiled()) {
181
+        if (!$this->isCompiled())
182
+        {
179 183
             $this->compile();
180 184
         }
181 185
 
@@ -185,8 +189,10 @@  discard block
 block discarded – undo
185 189
             $this->fetchOptions($parameters, $query)
186 190
         );
187 191
 
188
-        foreach ($this->constrains as $key => $_) {
189
-            if (empty($parameters[$key])) {
192
+        foreach ($this->constrains as $key => $_)
193
+        {
194
+            if (empty($parameters[$key]))
195
+            {
190 196
                 throw new UriHandlerException(\sprintf('Unable to generate Uri, parameter `%s` is missing', $key));
191 197
             }
192 198
         }
@@ -210,18 +216,23 @@  discard block
 block discarded – undo
210 216
         $allowed = \array_keys($this->options);
211 217
 
212 218
         $result = [];
213
-        foreach ($parameters as $key => $parameter) {
214
-            if (\is_int($key) && isset($allowed[$key])) {
219
+        foreach ($parameters as $key => $parameter)
220
+        {
221
+            if (\is_int($key) && isset($allowed[$key]))
222
+            {
215 223
                 // this segment fetched keys from given parameters either by name or by position
216 224
                 $key = $allowed[$key];
217
-            } elseif (!\array_key_exists($key, $this->options) && \is_array($parameters)) {
225
+            }
226
+            elseif (!\array_key_exists($key, $this->options) && \is_array($parameters))
227
+            {
218 228
                 // all additional parameters given in array form can be glued to query string
219 229
                 $query[$key] = $parameter;
220 230
                 continue;
221 231
             }
222 232
 
223 233
             //String must be normalized here
224
-            if (\is_string($parameter) && !\preg_match('/^[a-z\-_0-9]+$/i', $parameter)) {
234
+            if (\is_string($parameter) && !\preg_match('/^[a-z\-_0-9]+$/i', $parameter))
235
+            {
225 236
                 $result[$key] = $this->slugify->slugify($parameter);
226 237
                 continue;
227 238
             }
@@ -239,15 +250,20 @@  discard block
 block discarded – undo
239 250
     {
240 251
         $path = $uri->getPath();
241 252
 
242
-        if (empty($path) || $path[0] !== '/') {
253
+        if (empty($path) || $path[0] !== '/')
254
+        {
243 255
             $path = '/' . $path;
244 256
         }
245 257
 
246
-        if ($this->matchHost) {
258
+        if ($this->matchHost)
259
+        {
247 260
             $uriString = $uri->getHost() . $path;
248
-        } else {
261
+        }
262
+        else
263
+        {
249 264
             $uriString = \substr($path, \strlen($this->basePath));
250
-            if ($uriString === false) {
265
+            if ($uriString === false)
266
+            {
251 267
                 $uriString = '';
252 268
             }
253 269
         }
@@ -263,7 +279,8 @@  discard block
 block discarded – undo
263 279
      */
264 280
     private function compile(): void
265 281
     {
266
-        if ($this->pattern === null) {
282
+        if ($this->pattern === null)
283
+        {
267 284
             throw new UriHandlerException('Unable to compile UriHandler, pattern is not set');
268 285
         }
269 286
 
@@ -276,14 +293,17 @@  discard block
 block discarded – undo
276 293
         $pattern = \rtrim(\ltrim($pattern, ':/'), '/');
277 294
 
278 295
         // correct [/ first occurrence]
279
-        if (\str_starts_with($pattern, '[/')) {
296
+        if (\str_starts_with($pattern, '[/'))
297
+        {
280 298
             $pattern = '[' . \substr($pattern, 2);
281 299
         }
282 300
 
283
-        if (\preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) {
301
+        if (\preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches))
302
+        {
284 303
             $variables = \array_combine($matches[1], $matches[2]);
285 304
 
286
-            foreach ($variables as $key => $segment) {
305
+            foreach ($variables as $key => $segment)
306
+            {
287 307
                 $segment = $this->prepareSegment($key, $segment);
288 308
                 $replaces[\sprintf('<%s>', $key)] = \sprintf('(?P<%s>%s)', $key, $segment);
289 309
                 $options[] = $key;
@@ -293,13 +313,16 @@  discard block
 block discarded – undo
293 313
         $template = \preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern);
294 314
         $options = \array_fill_keys($options, null);
295 315
 
296
-        foreach ($this->constrains as $key => $value) {
297
-            if ($value instanceof Autofill) {
316
+        foreach ($this->constrains as $key => $value)
317
+        {
318
+            if ($value instanceof Autofill)
319
+            {
298 320
                 // only forces value replacement, not required to be presented as parameter
299 321
                 continue;
300 322
             }
301 323
 
302
-            if (!\array_key_exists($key, $options) && !isset($this->defaults[$key])) {
324
+            if (!\array_key_exists($key, $options) && !isset($this->defaults[$key]))
325
+            {
303 326
                 throw new ConstrainException(
304 327
                     \sprintf(
305 328
                         'Route `%s` does not define routing parameter `<%s>`.',
@@ -321,7 +344,8 @@  discard block
 block discarded – undo
321 344
     private function interpolate(string $string, array $values): string
322 345
     {
323 346
         $replaces = [];
324
-        foreach ($values as $key => $value) {
347
+        foreach ($values as $key => $value)
348
+        {
325 349
             $replaces[\sprintf('<%s>', $key)] = match (true) {
326 350
                 $value instanceof \Stringable || \is_scalar($value) => (string)$value,
327 351
                 default => '',
Please login to merge, or discard this patch.