Passed
Push — develop ( ab02c1...885544 )
by Andrew
04:19
created
src/services/Redirects.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
                 Craft::t(
86 86
                     'retour',
87 87
                     '404 URL: {url}',
88
-                    ['url' => $url]
88
+                    [ 'url' => $url ]
89 89
                 ),
90 90
                 __METHOD__
91 91
             );
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
     {
115 115
         $response = Craft::$app->getResponse();
116 116
         if ($redirect !== null) {
117
-            $dest = $redirect['redirectDestUrl'];
118
-            $status = $redirect['redirectHttpCode'];
117
+            $dest = $redirect[ 'redirectDestUrl' ];
118
+            $status = $redirect[ 'redirectHttpCode' ];
119 119
             Craft::info(
120 120
                 Craft::t(
121 121
                     'retour',
122 122
                     'Redirecting {url} to {dest} with status {status}',
123
-                    ['url' => $url, 'dest' => $dest, 'status' => $status]
123
+                    [ 'url' => $url, 'dest' => $dest, 'status' => $status ]
124 124
                 ),
125 125
                 __METHOD__
126 126
             );
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
     public function getRedirectFromCache($url)
173 173
     {
174 174
         $cache = Craft::$app->getCache();
175
-        $cacheKey = $this::CACHE_KEY.md5($url);
175
+        $cacheKey = $this::CACHE_KEY . md5($url);
176 176
         $redirect = $cache->get($cacheKey);
177 177
         Craft::info(
178 178
             Craft::t(
179 179
                 'retour',
180 180
                 'Cached redirect hit for {url}',
181
-                ['url' => $url]
181
+                [ 'url' => $url ]
182 182
             ),
183 183
             __METHOD__
184 184
         );
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public function saveRedirectToCache($url, $redirect)
194 194
     {
195
-        $cacheKey = $this::CACHE_KEY.md5($url);
195
+        $cacheKey = $this::CACHE_KEY . md5($url);
196 196
         $cache = Craft::$app->getCache();
197 197
         // Get the current site id
198 198
         $sites = Craft::$app->getSites();
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $dependency = new TagDependency([
206 206
             'tags' => [
207 207
                 $this::GLOBAL_REDIRECTS_CACHE_TAG,
208
-                $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId,
208
+                $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId,
209 209
             ],
210 210
         ]);
211 211
         $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency);
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             Craft::t(
214 214
                 'retour',
215 215
                 'Cached redirect saved for {url}',
216
-                ['url' => $url]
216
+                [ 'url' => $url ]
217 217
             ),
218 218
             __METHOD__
219 219
         );
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
     {
230 230
         $result = null;
231 231
         foreach ($redirects as $redirect) {
232
-            $redirectMatchType = $redirect['redirectMatchType'] ?? null;
232
+            $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? null;
233 233
             switch ($redirectMatchType) {
234 234
                 // Do a straight up match
235 235
                 case 'exactmatch':
236
-                    if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) {
236
+                    if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) {
237 237
                         $this->incrementRedirectHitCount($redirect);
238 238
                         $this->saveRedirectToCache($url, $redirect);
239 239
 
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 
244 244
                 // Do a regex match
245 245
                 case 'regexmatch':
246
-                    $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i';
246
+                    $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i';
247 247
                     if (preg_match($matchRegEx, $url) === 1) {
248 248
                         $this->incrementRedirectHitCount($redirect);
249 249
                         // If we're not associated with an EntryID, handle capture group replacement
250
-                        if ((int)$redirect['associatedElementId'] === 0) {
251
-                            $redirect['redirectDestUrl'] = preg_replace(
250
+                        if ((int) $redirect[ 'associatedElementId' ] === 0) {
251
+                            $redirect[ 'redirectDestUrl' ] = preg_replace(
252 252
                                 $matchRegEx,
253
-                                $redirect['redirectDestUrl'],
253
+                                $redirect[ 'redirectDestUrl' ],
254 254
                                 $url
255 255
                             );
256 256
                         }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
                                 'redirect' => &$redirect,
270 270
                             ],
271 271
                         ];
272
-                        $result = \call_user_func_array([$plugin, 'retourMatch'], $args);
272
+                        $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args);
273 273
                         if ($result) {
274 274
                             $this->incrementRedirectHitCount($redirect);
275 275
                             $this->saveRedirectToCache($url, $redirect);
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
             Craft::t(
285 285
                 'retour',
286 286
                 'Not handled: {url}',
287
-                ['url' => $url]
287
+                [ 'url' => $url ]
288 288
             ),
289 289
             __METHOD__
290 290
         );
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
         foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) {
309 309
             /** @var Plugin $plugin */
310 310
             if (method_exists($plugin, 'retourMatch')) {
311
-                $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match');
311
+                $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match');
312 312
             }
313 313
         }
314 314
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
         }
329 329
         // Query the db table
330 330
         $query = (new Query())
331
-            ->from(['{{%retour_static_redirects}}'])
331
+            ->from([ '{{%retour_static_redirects}}' ])
332 332
             ->orderBy('redirectMatchType ASC, hitCount DESC');
333 333
         if ($limit) {
334 334
             $query->limit($limit);
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
     {
352 352
         // Query the db table
353 353
         $redirect = (new Query())
354
-            ->from(['{{%retour_static_redirects}}'])
355
-            ->where(['id' => $id])
354
+            ->from([ '{{%retour_static_redirects}}' ])
355
+            ->where([ 'id' => $id ])
356 356
             ->one();
357 357
 
358 358
         return $redirect;
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
     public function incrementRedirectHitCount($redirectConfig)
393 393
     {
394 394
         if ($redirectConfig !== null) {
395
-            $redirectConfig['hitCount']++;
396
-            $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime());
395
+            $redirectConfig[ 'hitCount' ]++;
396
+            $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime());
397 397
             $this->saveRedirect($redirectConfig);
398 398
         }
399 399
     }
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
                 Craft::t(
411 411
                     'retour',
412 412
                     'Error validating redirect {id}: {errors}',
413
-                    ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)]
413
+                    [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ]
414 414
                 ),
415 415
                 __METHOD__
416 416
             );
@@ -421,25 +421,25 @@  discard block
 block discarded – undo
421 421
         $redirectConfig = $redirect->getAttributes();
422 422
         $db = Craft::$app->getDb();
423 423
         // See if a redirect exists with this source URL already
424
-        if ((int)$redirectConfig['id'] === 0) {
424
+        if ((int) $redirectConfig[ 'id' ] === 0) {
425 425
             // Query the db table
426 426
             $redirect = (new Query())
427
-                ->from(['{{%retour_static_redirects}}'])
428
-                ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']])
427
+                ->from([ '{{%retour_static_redirects}}' ])
428
+                ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ])
429 429
                 ->one();
430 430
             // If it exists, update it rather than having duplicates
431 431
             if (!empty($redirect)) {
432
-                $redirectConfig['id'] = $redirect['id'];
432
+                $redirectConfig[ 'id' ] = $redirect[ 'id' ];
433 433
             }
434 434
         }
435
-        if ((int)$redirectConfig['id'] !== 0) {
435
+        if ((int) $redirectConfig[ 'id' ] !== 0) {
436 436
             // Update the existing record
437 437
             try {
438 438
                 $db->createCommand()->update(
439 439
                     '{{%retour_static_redirects}}',
440 440
                     $redirectConfig,
441 441
                     [
442
-                        'id' => $redirectConfig['id'],
442
+                        'id' => $redirectConfig[ 'id' ],
443 443
                     ]
444 444
                 )->execute();
445 445
             } catch (Exception $e) {
Please login to merge, or discard this patch.