Passed
Push — develop ( 4666f6...f02416 )
by Andrew
05:59
created
src/Retour.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     /**
122 122
      * @var array The URIs for the element before it was saved
123 123
      */
124
-    public $oldElementUris = [];
124
+    public $oldElementUris = [ ];
125 125
 
126 126
     // Public Methods
127 127
     // =========================================================================
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
             Craft::t(
155 155
                 'retour',
156 156
                 '{name} plugin loaded',
157
-                ['name' => $this->name]
157
+                [ 'name' => $this->name ]
158 158
             ),
159 159
             __METHOD__
160 160
         );
@@ -174,18 +174,18 @@  discard block
 block discarded – undo
174 174
      */
175 175
     public function getCpNavItem()
176 176
     {
177
-        $subNavs = [];
177
+        $subNavs = [ ];
178 178
         $navItem = parent::getCpNavItem();
179 179
         $currentUser = Craft::$app->getUser()->getIdentity();
180 180
         // Only show sub-navs the user has permission to view
181 181
         if ($currentUser->can('retour:dashboard')) {
182
-            $subNavs['dashboard'] = [
182
+            $subNavs[ 'dashboard' ] = [
183 183
                 'label' => 'Dashboard',
184 184
                 'url' => 'retour/dashboard',
185 185
             ];
186 186
         }
187 187
         if ($currentUser->can('retour:redirects')) {
188
-            $subNavs['redirects'] = [
188
+            $subNavs[ 'redirects' ] = [
189 189
                 'label' => 'Redirects',
190 190
                 'url' => 'retour/redirects',
191 191
             ];
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             $editableSettings = false;
197 197
         }
198 198
         if ($currentUser->can('retour:settings') && $editableSettings) {
199
-            $subNavs['settings'] = [
199
+            $subNavs[ 'settings' ] = [
200 200
                 'label' => 'Settings',
201 201
                 'url' => 'retour/settings',
202 202
             ];
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         Event::on(
256 256
             ClearCaches::class,
257 257
             ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
258
-            function (RegisterCacheOptionsEvent $event) {
258
+            function(RegisterCacheOptionsEvent $event) {
259 259
                 Craft::debug(
260 260
                     'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS',
261 261
                     __METHOD__
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         Event::on(
272 272
             Plugins::class,
273 273
             Plugins::EVENT_AFTER_INSTALL_PLUGIN,
274
-            function (PluginEvent $event) {
274
+            function(PluginEvent $event) {
275 275
                 if ($event->plugin === $this) {
276 276
                     // Invalidate our caches after we've been installed
277 277
                     $this->clearAllCaches();
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         Event::on(
299 299
             CraftVariable::class,
300 300
             CraftVariable::EVENT_INIT,
301
-            function (Event $event) {
301
+            function(Event $event) {
302 302
                 /** @var CraftVariable $variable */
303 303
                 $variable = $event->sender;
304 304
                 $variable->set('retour', RetourVariable::class);
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
         Event::on(
309 309
             Elements::class,
310 310
             Elements::EVENT_BEFORE_SAVE_ELEMENT,
311
-            function (ElementEvent $event) {
311
+            function(ElementEvent $event) {
312 312
                 Craft::debug(
313 313
                     'Elements::EVENT_BEFORE_SAVE_ELEMENT',
314 314
                     __METHOD__
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
                         if (strpos($element->uri, '__temp_') === false && !$element->propagating) {
334 334
                             // Stash the old URLs by element id, and do so only once,
335 335
                             // in case we are called more than once per request
336
-                            if (empty($this->oldElementUris[$element->id])) {
337
-                                $this->oldElementUris[$element->id] = $this->getAllElementUris($element);
336
+                            if (empty($this->oldElementUris[ $element->id ])) {
337
+                                $this->oldElementUris[ $element->id ] = $this->getAllElementUris($element);
338 338
                             }
339 339
                         }
340 340
                     }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
         Event::on(
346 346
             Elements::class,
347 347
             Elements::EVENT_AFTER_SAVE_ELEMENT,
348
-            function (ElementEvent $event) {
348
+            function(ElementEvent $event) {
349 349
                 Craft::debug(
350 350
                     'Elements::EVENT_AFTER_SAVE_ELEMENT',
351 351
                     __METHOD__
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
         Event::on(
368 368
             Plugins::class,
369 369
             Plugins::EVENT_AFTER_LOAD_PLUGINS,
370
-            function () {
370
+            function() {
371 371
                 // Install these only after all other plugins have loaded
372 372
                 $request = Craft::$app->getRequest();
373 373
                 // Only respond to non-console site requests
@@ -385,26 +385,26 @@  discard block
 block discarded – undo
385 385
             Event::on(
386 386
                 Gql::class,
387 387
                 Gql::EVENT_REGISTER_GQL_TYPES,
388
-                function (RegisterGqlTypesEvent $event) {
388
+                function(RegisterGqlTypesEvent $event) {
389 389
                     Craft::debug(
390 390
                         'Gql::EVENT_REGISTER_GQL_TYPES',
391 391
                         __METHOD__
392 392
                     );
393
-                    $event->types[] = RetourInterface::class;
393
+                    $event->types[ ] = RetourInterface::class;
394 394
                 }
395 395
             );
396 396
             // Handler: Gql::EVENT_REGISTER_GQL_QUERIES
397 397
             Event::on(
398 398
                 Gql::class,
399 399
                 Gql::EVENT_REGISTER_GQL_QUERIES,
400
-                function (RegisterGqlQueriesEvent $event) {
400
+                function(RegisterGqlQueriesEvent $event) {
401 401
                     Craft::debug(
402 402
                         'Gql::EVENT_REGISTER_GQL_QUERIES',
403 403
                         __METHOD__
404 404
                     );
405 405
                     $queries = RetourQuery::getQueries();
406 406
                     foreach ($queries as $key => $value) {
407
-                        $event->queries[$key] = $value;
407
+                        $event->queries[ $key ] = $value;
408 408
                     }
409 409
                 }
410 410
             );
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
             Event::on(
415 415
                 Schema::class,
416 416
                 AlterSchemaFields::EVENT,
417
-                [GetCraftQLSchema::class, 'handle']
417
+                [ GetCraftQLSchema::class, 'handle' ]
418 418
             );
419 419
         }
420 420
     }
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
         Event::on(
429 429
             UrlManager::class,
430 430
             UrlManager::EVENT_REGISTER_SITE_URL_RULES,
431
-            function (RegisterUrlRulesEvent $event) {
431
+            function(RegisterUrlRulesEvent $event) {
432 432
                 Craft::debug(
433 433
                     'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
434 434
                     __METHOD__
@@ -451,15 +451,15 @@  discard block
 block discarded – undo
451 451
         Event::on(
452 452
             Dashboard::class,
453 453
             Dashboard::EVENT_REGISTER_WIDGET_TYPES,
454
-            function (RegisterComponentTypesEvent $event) {
455
-                $event->types[] = RetourWidget::class;
454
+            function(RegisterComponentTypesEvent $event) {
455
+                $event->types[ ] = RetourWidget::class;
456 456
             }
457 457
         );
458 458
         // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES
459 459
         Event::on(
460 460
             UrlManager::class,
461 461
             UrlManager::EVENT_REGISTER_CP_URL_RULES,
462
-            function (RegisterUrlRulesEvent $event) {
462
+            function(RegisterUrlRulesEvent $event) {
463 463
                 Craft::debug(
464 464
                     'UrlManager::EVENT_REGISTER_CP_URL_RULES',
465 465
                     __METHOD__
@@ -475,13 +475,13 @@  discard block
 block discarded – undo
475 475
         Event::on(
476 476
             UserPermissions::class,
477 477
             UserPermissions::EVENT_REGISTER_PERMISSIONS,
478
-            function (RegisterUserPermissionsEvent $event) {
478
+            function(RegisterUserPermissionsEvent $event) {
479 479
                 Craft::debug(
480 480
                     'UserPermissions::EVENT_REGISTER_PERMISSIONS',
481 481
                     __METHOD__
482 482
                 );
483 483
                 // Register our custom permissions
484
-                $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions();
484
+                $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions();
485 485
             }
486 486
         );
487 487
     }
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
         Event::on(
498 498
             ErrorHandler::class,
499 499
             ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
500
-            function (ExceptionEvent $event) {
500
+            function(ExceptionEvent $event) {
501 501
                 Craft::debug(
502 502
                     'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION',
503 503
                     __METHOD__
@@ -540,16 +540,16 @@  discard block
 block discarded – undo
540 540
     protected function handleElementUriChange(Element $element)
541 541
     {
542 542
         $uris = $this->getAllElementUris($element);
543
-        if (!empty($this->oldElementUris[$element->id])) {
544
-            $oldElementUris = $this->oldElementUris[$element->id];
543
+        if (!empty($this->oldElementUris[ $element->id ])) {
544
+            $oldElementUris = $this->oldElementUris[ $element->id ];
545 545
             foreach ($uris as $siteId => $newUri) {
546
-                if (!empty($oldElementUris[$siteId])) {
547
-                    $oldUri = $oldElementUris[$siteId];
546
+                if (!empty($oldElementUris[ $siteId ])) {
547
+                    $oldUri = $oldElementUris[ $siteId ];
548 548
                     Craft::debug(
549 549
                         Craft::t(
550 550
                             'retour',
551 551
                             'Comparing old: {oldUri} to new: {newUri}',
552
-                            ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)]
552
+                            [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ]
553 553
                         ),
554 554
                         __METHOD__
555 555
                     );
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
                         if (self::$settings->uriChangeRedirectSrcMatch === 'fullurl') {
570 570
                             try {
571 571
                                 if ($redirectSiteId !== null) {
572
-                                    $redirectSiteId = (int)$redirectSiteId;
572
+                                    $redirectSiteId = (int) $redirectSiteId;
573 573
                                 }
574 574
                                 $oldUri = UrlHelper::siteUrl($oldUri, null, null, $redirectSiteId);
575 575
                                 $newUri = UrlHelper::siteUrl($newUri, null, null, $redirectSiteId);
@@ -602,13 +602,13 @@  discard block
 block discarded – undo
602 602
      */
603 603
     protected function getAllElementUris(Element $element): array
604 604
     {
605
-        $uris = [];
605
+        $uris = [ ];
606 606
         if (!self::$craft32 || !ElementHelper::isDraftOrRevision($element)) {
607 607
             $sites = Craft::$app->getSites()->getAllSites();
608 608
             foreach ($sites as $site) {
609 609
                 $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id);
610 610
                 if ($uri !== null) {
611
-                    $uris[$site->id] = $uri;
611
+                    $uris[ $site->id ] = $uri;
612 612
                 }
613 613
             }
614 614
         }
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
             Craft::t(
618 618
                 'retour',
619 619
                 'Getting Element URIs: {uris}',
620
-                ['uris' => print_r($uris, true)]
620
+                [ 'uris' => print_r($uris, true) ]
621 621
             ),
622 622
             __METHOD__
623 623
         );
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
             [
673 673
                 'key' => 'retour-redirect-caches',
674 674
                 'label' => Craft::t('retour', 'Retour redirect caches'),
675
-                'action' => [self::$plugin->redirects, 'invalidateCaches'],
675
+                'action' => [ self::$plugin->redirects, 'invalidateCaches' ],
676 676
             ],
677 677
         ];
678 678
     }
Please login to merge, or discard this patch.
src/helpers/UrlHelper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
         /** @noinspection CallableParameterUseCaseInTypeContextInspection */
40 40
         $url = preg_replace('/{.*}/', '', $url);
41 41
         // Remove any linebreaks that may be errantly in the URL
42
-        $url = (string)str_replace([
42
+        $url = (string) str_replace([
43 43
             PHP_EOL,
44 44
                 "\r",
45 45
                 "\n",
Please login to merge, or discard this patch.
src/controllers/ApiController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,6 +57,6 @@
 block discarded – undo
57 57
     {
58 58
         $redirects = Retour::$plugin->redirects->getAllStaticRedirects(null, $siteId);
59 59
 
60
-        return $this->asJson($redirects ?? []);
60
+        return $this->asJson($redirects ?? [ ]);
61 61
     }
62 62
 }
Please login to merge, or discard this patch.
src/models/Settings.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
     public function rules()
136 136
     {
137 137
         return [
138
-            ['pluginName', 'string'],
139
-            ['pluginName', 'default', 'value' => 'Retour'],
138
+            [ 'pluginName', 'string' ],
139
+            [ 'pluginName', 'default', 'value' => 'Retour' ],
140 140
             [
141 141
                 [
142 142
                     'createUriChangeRedirects',
@@ -147,22 +147,22 @@  discard block
 block discarded – undo
147 147
                 ],
148 148
                 'boolean',
149 149
             ],
150
-            ['uriChangeRedirectSrcMatch', 'default', 'value' => 'pathonly'],
151
-            ['uriChangeRedirectSrcMatch', 'string'],
152
-            ['uriChangeRedirectSrcMatch', 'in', 'range' => [
150
+            [ 'uriChangeRedirectSrcMatch', 'default', 'value' => 'pathonly' ],
151
+            [ 'uriChangeRedirectSrcMatch', 'string' ],
152
+            [ 'uriChangeRedirectSrcMatch', 'in', 'range' => [
153 153
                 'pathonly',
154 154
                 'fullurl'
155
-            ]],
156
-            ['staticRedirectDisplayLimit', 'integer', 'min' => 1],
157
-            ['staticRedirectDisplayLimit', 'default', 'value' => 100],
158
-            ['dynamicRedirectDisplayLimit', 'integer', 'min' => 1],
159
-            ['dynamicRedirectDisplayLimit', 'default', 'value' => 100],
160
-            ['statsStoredLimit', 'integer', 'min' => 1],
161
-            ['statsStoredLimit', 'default', 'value' => 1000],
162
-            ['refreshIntervalSecs', 'integer', 'min' => 0],
163
-            ['refreshIntervalSecs', 'default', 'value' => 3],
164
-            ['statsDisplayLimit', 'integer', 'min' => 1],
165
-            ['statsDisplayLimit', 'default', 'value' => 1000],
155
+            ] ],
156
+            [ 'staticRedirectDisplayLimit', 'integer', 'min' => 1 ],
157
+            [ 'staticRedirectDisplayLimit', 'default', 'value' => 100 ],
158
+            [ 'dynamicRedirectDisplayLimit', 'integer', 'min' => 1 ],
159
+            [ 'dynamicRedirectDisplayLimit', 'default', 'value' => 100 ],
160
+            [ 'statsStoredLimit', 'integer', 'min' => 1 ],
161
+            [ 'statsStoredLimit', 'default', 'value' => 1000 ],
162
+            [ 'refreshIntervalSecs', 'integer', 'min' => 0 ],
163
+            [ 'refreshIntervalSecs', 'default', 'value' => 3 ],
164
+            [ 'statsDisplayLimit', 'integer', 'min' => 1 ],
165
+            [ 'statsDisplayLimit', 'default', 'value' => 1000 ],
166 166
             [
167 167
                 [
168 168
                     'excludePatterns',
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public function behaviors()
180 180
     {
181
-        $craft31Behaviors = [];
181
+        $craft31Behaviors = [ ];
182 182
         if (Retour::$craft31) {
183 183
             $craft31Behaviors = [
184 184
                 'parser' => [
Please login to merge, or discard this patch.
src/config.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
     // Determines whether the Retour API endpoint should be enabled for anonymous frontend access
58 58
     'enableApiEndpoint' => false,
59 59
 
60
-     // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking
60
+        // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking
61 61
     'excludePatterns' => [
62 62
     ],
63 63
 
Please login to merge, or discard this patch.
src/controllers/RedirectsController.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     // Protected Properties
42 42
     // =========================================================================
43 43
 
44
-    protected $allowAnonymous = [];
44
+    protected $allowAnonymous = [ ];
45 45
 
46 46
     // Public Methods
47 47
     // =========================================================================
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function actionRedirects(string $siteHandle = null): Response
59 59
     {
60
-        $variables = [];
60
+        $variables = [ ];
61 61
         PermissionHelper::controllerPermissionCheck('retour:redirects');
62 62
         // Get the site to edit
63 63
         $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle);
@@ -70,32 +70,32 @@  discard block
 block discarded – undo
70 70
         } catch (InvalidConfigException $e) {
71 71
             Craft::error($e->getMessage(), __METHOD__);
72 72
         }
73
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
73
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
74 74
             '@nystudio107/retour/assetbundles/retour/dist',
75 75
             true
76 76
         );
77 77
         // Enabled sites
78 78
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
79
-        $variables['controllerHandle'] = 'redirects';
79
+        $variables[ 'controllerHandle' ] = 'redirects';
80 80
 
81 81
         // Basic variables
82
-        $variables['fullPageForm'] = false;
83
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
84
-        $variables['pluginName'] = $pluginName;
85
-        $variables['title'] = $templateTitle;
86
-        $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : '';
87
-        $variables['crumbs'] = [
82
+        $variables[ 'fullPageForm' ] = false;
83
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
84
+        $variables[ 'pluginName' ] = $pluginName;
85
+        $variables[ 'title' ] = $templateTitle;
86
+        $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : '';
87
+        $variables[ 'crumbs' ] = [
88 88
             [
89 89
                 'label' => $pluginName,
90 90
                 'url' => UrlHelper::cpUrl('retour'),
91 91
             ],
92 92
             [
93 93
                 'label' => $templateTitle,
94
-                'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri),
94
+                'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri),
95 95
             ],
96 96
         ];
97
-        $variables['docTitle'] = "{$pluginName} - {$templateTitle}";
98
-        $variables['selectedSubnavItem'] = 'redirects';
97
+        $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}";
98
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
99 99
 
100 100
         // Render the template
101 101
         return $this->renderTemplate('retour/redirects/index', $variables);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         int $siteId = 0,
120 120
         StaticRedirectsModel $redirect = null
121 121
     ): Response {
122
-        $variables = [];
122
+        $variables = [ ];
123 123
         PermissionHelper::controllerPermissionCheck('retour:redirects');
124 124
 
125 125
         // Load in the redirect
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
         if ($redirect === null) {
134 134
             $redirectConfig = Retour::$plugin->redirects->getRedirectById($redirectId);
135 135
             if ($redirectConfig === null) {
136
-                $redirectConfig = [];
136
+                $redirectConfig = [ ];
137 137
                 Craft::error(
138 138
                     Craft::t(
139 139
                         'retour',
140 140
                         "Couldn't load redirect id {id}",
141
-                        ['id' => $redirectId]
141
+                        [ 'id' => $redirectId ]
142 142
                     ),
143 143
                     __METHOD__
144 144
                 );
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
         if ($redirect->siteId) {
152 152
             $site = $sites->getSiteById($redirect->siteId);
153 153
             if ($site) {
154
-                MultiSiteHelper::requirePermission('editSite:'.$site->uid);
154
+                MultiSiteHelper::requirePermission('editSite:' . $site->uid);
155 155
             }
156 156
         }
157 157
         if ($siteId) {
158 158
             $site = $sites->getSiteById($siteId);
159 159
             if ($site) {
160
-                MultiSiteHelper::requirePermission('editSite:'.$site->uid);
160
+                MultiSiteHelper::requirePermission('editSite:' . $site->uid);
161 161
             }
162 162
         }
163 163
         $pluginName = Retour::$settings->pluginName;
@@ -169,20 +169,20 @@  discard block
 block discarded – undo
169 169
         } catch (InvalidConfigException $e) {
170 170
             Craft::error($e->getMessage(), __METHOD__);
171 171
         }
172
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
172
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
173 173
             '@nystudio107/retour/assetbundles/retour/dist',
174 174
             true
175 175
         );
176 176
         // Sites menu
177 177
         MultiSiteHelper::setSitesMenuVariables($variables);
178
-        $variables['controllerHandle'] = 'redirects';
178
+        $variables[ 'controllerHandle' ] = 'redirects';
179 179
 
180 180
         // Basic variables
181
-        $variables['fullPageForm'] = true;
182
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
183
-        $variables['pluginName'] = $pluginName;
184
-        $variables['title'] = $templateTitle;
185
-        $variables['crumbs'] = [
181
+        $variables[ 'fullPageForm' ] = true;
182
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
183
+        $variables[ 'pluginName' ] = $pluginName;
184
+        $variables[ 'title' ] = $templateTitle;
185
+        $variables[ 'crumbs' ] = [
186 186
             [
187 187
                 'label' => $pluginName,
188 188
                 'url' => UrlHelper::cpUrl('retour'),
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
             ],
194 194
             [
195 195
                 'label' => $templateTitle,
196
-                'url' => UrlHelper::cpUrl('retour/edit-redirect/'.$redirectId),
196
+                'url' => UrlHelper::cpUrl('retour/edit-redirect/' . $redirectId),
197 197
             ],
198 198
         ];
199
-        $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}";
200
-        $variables['selectedSubnavItem'] = 'redirects';
201
-        $variables['redirect'] = $redirect;
199
+        $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}";
200
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
201
+        $variables[ 'redirect' ] = $redirect;
202 202
 
203 203
         // Render the template
204 204
         return $this->renderTemplate('retour/redirects/_edit', $variables);
@@ -251,12 +251,12 @@  discard block
 block discarded – undo
251 251
         if ($redirectConfig === null) {
252 252
             throw new NotFoundHttpException('Redirect not found');
253 253
         }
254
-        $redirectConfig['id'] = (int)$redirectConfig['id'];
254
+        $redirectConfig[ 'id' ] = (int) $redirectConfig[ 'id' ];
255 255
         // Handle enforcing trailing slashes
256 256
         $generalConfig = Craft::$app->getConfig()->getGeneral();
257
-        if ($generalConfig->addTrailingSlashesToUrls && $redirectConfig['redirectMatchType'] === 'exactmatch') {
258
-            $destUrl = $redirectConfig['redirectDestUrl'] ?? '';
259
-            $redirectConfig['redirectDestUrl'] = $this->addSlashToSiteUrls($destUrl);
257
+        if ($generalConfig->addTrailingSlashesToUrls && $redirectConfig[ 'redirectMatchType' ] === 'exactmatch') {
258
+            $destUrl = $redirectConfig[ 'redirectDestUrl' ] ?? '';
259
+            $redirectConfig[ 'redirectDestUrl' ] = $this->addSlashToSiteUrls($destUrl);
260 260
         }
261 261
         $redirect = new StaticRedirectsModel($redirectConfig);
262 262
         // Make sure the redirect validates
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
         Retour::$plugin->redirects->saveRedirect($redirectConfig);
275 275
         // Handle the case where the redirect wasn't saved because it'd create a redirect loop
276 276
         $testRedirectConfig = Retour::$plugin->redirects->getRedirectByRedirectSrcUrl(
277
-            $redirectConfig['redirectSrcUrl'],
278
-            $redirectConfig['siteId']
277
+            $redirectConfig[ 'redirectSrcUrl' ],
278
+            $redirectConfig[ 'siteId' ]
279 279
         );
280 280
         if ($testRedirectConfig === null) {
281 281
             Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save redirect settings because it'd create a redirect loop."));
Please login to merge, or discard this patch.
src/services/Redirects.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
                 Craft::t(
191 191
                     'retour',
192 192
                     '404 full URL: {fullUrl}, 404 path only: {pathOnly}',
193
-                    ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly]
193
+                    [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ]
194 194
                 ),
195 195
                 __METHOD__
196 196
             );
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
         $response = Craft::$app->getResponse();
225 225
         if ($redirect !== null) {
226 226
             // Figure out what type of source matching was done
227
-            $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly';
227
+            $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly';
228 228
             switch ($redirectSrcMatch) {
229 229
                 case 'pathonly':
230 230
                     $url = $pathOnly;
@@ -236,13 +236,13 @@  discard block
 block discarded – undo
236 236
                     $url = $pathOnly;
237 237
                     break;
238 238
             }
239
-            $dest = $redirect['redirectDestUrl'];
239
+            $dest = $redirect[ 'redirectDestUrl' ];
240 240
             // If this isn't a full URL, make it one based on the appropriate site
241 241
             if (!UrlHelper::isFullUrl($dest)) {
242 242
                 try {
243
-                    $siteId = $redirect['siteId'] ?? null;
243
+                    $siteId = $redirect[ 'siteId' ] ?? null;
244 244
                     if ($siteId !== null) {
245
-                        $siteId = (int)$siteId;
245
+                        $siteId = (int) $siteId;
246 246
                     }
247 247
                     $dest = UrlHelper::siteUrl($dest, null, null, $siteId);
248 248
                 } catch (\yii\base\Exception $e) {
@@ -254,17 +254,17 @@  discard block
 block discarded – undo
254 254
                     $dest .= '?' . $request->getQueryStringWithoutPath();
255 255
                 }
256 256
             }
257
-            $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound';
257
+            $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound';
258 258
             // Parse reference tags for exact matches
259 259
             if ($redirectMatchType === 'exactmatch') {
260
-                $dest = Craft::$app->elements->parseRefs($dest, $redirect['siteId'] ?? null);
260
+                $dest = Craft::$app->elements->parseRefs($dest, $redirect[ 'siteId' ] ?? null);
261 261
             }
262
-            $status = $redirect['redirectHttpCode'];
262
+            $status = $redirect[ 'redirectHttpCode' ];
263 263
             Craft::info(
264 264
                 Craft::t(
265 265
                     'retour',
266 266
                     'Redirecting {url} to {dest} with status {status}',
267
-                    ['url' => $url, 'dest' => $dest, 'status' => $status]
267
+                    [ 'url' => $url, 'dest' => $dest, 'status' => $status ]
268 268
                 ),
269 269
                 __METHOD__
270 270
             );
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
             // Add any additional headers (existing ones will be replaced)
289 289
             if (!empty(Retour::$settings->additionalHeaders)) {
290 290
                 foreach (Retour::$settings->additionalHeaders as $additionalHeader) {
291
-                    $response->headers->set($additionalHeader['name'], $additionalHeader['value']);
291
+                    $response->headers->set($additionalHeader[ 'name' ], $additionalHeader[ 'value' ]);
292 292
                 }
293 293
             }
294 294
             // Redirect the request away;
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
     public function getRedirectFromCache($url, int $siteId = 0)
355 355
     {
356 356
         $cache = Craft::$app->getCache();
357
-        $cacheKey = $this::CACHE_KEY.md5($url).$siteId;
357
+        $cacheKey = $this::CACHE_KEY . md5($url) . $siteId;
358 358
         $redirect = $cache->get($cacheKey);
359 359
         Craft::info(
360 360
             Craft::t(
361 361
                 'retour',
362 362
                 'Cached redirect hit for {url}',
363
-                ['url' => $url]
363
+                [ 'url' => $url ]
364 364
             ),
365 365
             __METHOD__
366 366
         );
@@ -382,12 +382,12 @@  discard block
 block discarded – undo
382 382
         } catch (SiteNotFoundException $e) {
383 383
             $siteId = 1;
384 384
         }
385
-        $cacheKey = $this::CACHE_KEY.md5($url).$siteId;
385
+        $cacheKey = $this::CACHE_KEY . md5($url) . $siteId;
386 386
         // Create the dependency tags
387 387
         $dependency = new TagDependency([
388 388
             'tags' => [
389 389
                 $this::GLOBAL_REDIRECTS_CACHE_TAG,
390
-                $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId,
390
+                $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId,
391 391
             ],
392 392
         ]);
393 393
         $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency);
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             Craft::t(
396 396
                 'retour',
397 397
                 'Cached redirect saved for {url}',
398
-                ['url' => $url]
398
+                [ 'url' => $url ]
399 399
             ),
400 400
             __METHOD__
401 401
         );
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
         // Iterate through the redirects
426 426
         foreach ($redirects as $redirect) {
427 427
             // Figure out what type of source matching to do
428
-            $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly';
429
-            $redirectEnabled = (bool)$redirect['enabled'];
428
+            $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly';
429
+            $redirectEnabled = (bool) $redirect[ 'enabled' ];
430 430
             if ($redirectEnabled === true) {
431 431
                 switch ($redirectSrcMatch) {
432 432
                     case 'pathonly':
@@ -439,11 +439,11 @@  discard block
 block discarded – undo
439 439
                         $url = $pathOnly;
440 440
                         break;
441 441
                 }
442
-                $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound';
442
+                $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound';
443 443
                 switch ($redirectMatchType) {
444 444
                     // Do a straight up match
445 445
                     case 'exactmatch':
446
-                        if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) {
446
+                        if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) {
447 447
                             $this->incrementRedirectHitCount($redirect);
448 448
                             $this->saveRedirectToCache($url, $redirect);
449 449
 
@@ -466,15 +466,15 @@  discard block
 block discarded – undo
466 466
 
467 467
                     // Do a regex match
468 468
                     case 'regexmatch':
469
-                        $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i';
469
+                        $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i';
470 470
                         try {
471 471
                             if (preg_match($matchRegEx, $url) === 1) {
472 472
                                 $this->incrementRedirectHitCount($redirect);
473 473
                                 // If we're not associated with an EntryID, handle capture group replacement
474
-                                if ((int)$redirect['associatedElementId'] === 0) {
475
-                                    $redirect['redirectDestUrl'] = preg_replace(
474
+                                if ((int) $redirect[ 'associatedElementId' ] === 0) {
475
+                                    $redirect[ 'redirectDestUrl' ] = preg_replace(
476 476
                                         $matchRegEx,
477
-                                        $redirect['redirectDestUrl'],
477
+                                        $redirect[ 'redirectDestUrl' ],
478 478
                                         $url
479 479
                                     );
480 480
                                 }
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
                             }
499 499
                         } catch (\Exception $e) {
500 500
                             // That's fine
501
-                            Craft::error('Invalid Redirect Regex: '.$matchRegEx, __METHOD__);
501
+                            Craft::error('Invalid Redirect Regex: ' . $matchRegEx, __METHOD__);
502 502
                         }
503 503
 
504 504
                         break;
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
                                     'redirect' => &$redirect,
513 513
                                 ],
514 514
                             ];
515
-                            $result = \call_user_func_array([$plugin, 'retourMatch'], $args);
515
+                            $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args);
516 516
                             if ($result) {
517 517
                                 $this->incrementRedirectHitCount($redirect);
518 518
                                 $this->saveRedirectToCache($url, $redirect);
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
             Craft::t(
553 553
                 'retour',
554 554
                 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}',
555
-                ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly]
555
+                [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ]
556 556
             ),
557 557
             __METHOD__
558 558
         );
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
 
580 580
             if ($url !== null && $redirect !== null) {
581 581
                 // Save the modified redirect to the cache
582
-                $redirect['redirectDestUrl'] = $event->redirectDestUrl;
583
-                $redirect['redirectHttpCode'] = $event->redirectHttpCode;
582
+                $redirect[ 'redirectDestUrl' ] = $event->redirectDestUrl;
583
+                $redirect[ 'redirectHttpCode' ] = $event->redirectHttpCode;
584 584
                 $this->saveRedirectToCache($url, $redirect);
585 585
             }
586 586
         }
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
         foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) {
605 605
             /** @var Plugin $plugin */
606 606
             if (method_exists($plugin, 'retourMatch')) {
607
-                $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match');
607
+                $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match');
608 608
             }
609 609
         }
610 610
 
@@ -625,12 +625,12 @@  discard block
 block discarded – undo
625 625
         }
626 626
         // Query the db table
627 627
         $query = (new Query())
628
-            ->from(['{{%retour_static_redirects}}'])
628
+            ->from([ '{{%retour_static_redirects}}' ])
629 629
             ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC');
630 630
         if ($siteId) {
631 631
             $query
632
-                ->where(['siteId' => $siteId])
633
-                ->orWhere(['siteId' => null]);
632
+                ->where([ 'siteId' => $siteId ])
633
+                ->orWhere([ 'siteId' => null ]);
634 634
         }
635 635
         if ($limit) {
636 636
             $query->limit($limit);
@@ -653,8 +653,8 @@  discard block
 block discarded – undo
653 653
     {
654 654
         // Query the db table
655 655
         $redirect = (new Query())
656
-            ->from(['{{%retour_static_redirects}}'])
657
-            ->where(['id' => $id])
656
+            ->from([ '{{%retour_static_redirects}}' ])
657
+            ->where([ 'id' => $id ])
658 658
             ->one();
659 659
 
660 660
         return $redirect;
@@ -672,16 +672,16 @@  discard block
 block discarded – undo
672 672
     {
673 673
         // Query the db table
674 674
         $query = (new Query())
675
-            ->from(['{{%retour_static_redirects}}'])
676
-            ->where(['redirectSrcUrl' => $redirectSrcUrl])
675
+            ->from([ '{{%retour_static_redirects}}' ])
676
+            ->where([ 'redirectSrcUrl' => $redirectSrcUrl ])
677 677
             ;
678 678
         if ($siteId) {
679 679
             $query
680
-                ->andWhere(['or', [
680
+                ->andWhere([ 'or', [
681 681
                     'siteId' => $siteId,
682 682
                 ], [
683 683
                     'siteId' => null,
684
-                ]]);
684
+                ] ]);
685 685
         }
686 686
         $redirect = $query->one();
687 687
 
@@ -723,13 +723,13 @@  discard block
 block discarded – undo
723 723
     {
724 724
         if ($redirectConfig !== null) {
725 725
             $db = Craft::$app->getDb();
726
-            $redirectConfig['hitCount']++;
727
-            $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime());
726
+            $redirectConfig[ 'hitCount' ]++;
727
+            $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime());
728 728
             Craft::debug(
729 729
                 Craft::t(
730 730
                     'retour',
731 731
                     'Incrementing statistics for: {redirect}',
732
-                    ['redirect' => print_r($redirectConfig, true)]
732
+                    [ 'redirect' => print_r($redirectConfig, true) ]
733 733
                 ),
734 734
                 __METHOD__
735 735
             );
@@ -738,14 +738,14 @@  discard block
 block discarded – undo
738 738
                 $rowsAffected = $db->createCommand()->update(
739 739
                     '{{%retour_static_redirects}}',
740 740
                     [
741
-                        'hitCount' => $redirectConfig['hitCount'],
742
-                        'hitLastTime' => $redirectConfig['hitLastTime'],
741
+                        'hitCount' => $redirectConfig[ 'hitCount' ],
742
+                        'hitLastTime' => $redirectConfig[ 'hitLastTime' ],
743 743
                     ],
744 744
                     [
745
-                        'id' => $redirectConfig['id'],
745
+                        'id' => $redirectConfig[ 'id' ],
746 746
                     ]
747 747
                 )->execute();
748
-                Craft::debug('Rows affected: '.$rowsAffected, __METHOD__);
748
+                Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__);
749 749
             } catch (\Exception $e) {
750 750
                 Craft::error($e->getMessage(), __METHOD__);
751 751
             }
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
                 Craft::t(
765 765
                     'retour',
766 766
                     'Error validating redirect {id}: {errors}',
767
-                    ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)]
767
+                    [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ]
768 768
                 ),
769 769
                 __METHOD__
770 770
             );
@@ -774,32 +774,32 @@  discard block
 block discarded – undo
774 774
         // Get the validated model attributes and save them to the db
775 775
         $redirectConfig = $redirect->getAttributes();
776 776
         // 0 for a siteId needs to be converted to null
777
-        if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) {
778
-            $redirectConfig['siteId'] = null;
777
+        if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) {
778
+            $redirectConfig[ 'siteId' ] = null;
779 779
         }
780 780
         // Throw an event to before saving the redirect
781 781
         $db = Craft::$app->getDb();
782 782
         // See if a redirect exists with this source URL already
783
-        if ((int)$redirectConfig['id'] === 0) {
783
+        if ((int) $redirectConfig[ 'id' ] === 0) {
784 784
             // Query the db table
785 785
             $redirect = (new Query())
786
-                ->from(['{{%retour_static_redirects}}'])
787
-                ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']])
788
-                ->andWhere(['siteId' => $redirectConfig['siteId']])
786
+                ->from([ '{{%retour_static_redirects}}' ])
787
+                ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ])
788
+                ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ])
789 789
                 ->one();
790 790
             // If it exists, update it rather than having duplicates
791 791
             if (!empty($redirect)) {
792
-                $redirectConfig['id'] = $redirect['id'];
792
+                $redirectConfig[ 'id' ] = $redirect[ 'id' ];
793 793
             }
794 794
         }
795 795
         // Trigger a 'beforeSaveRedirect' event
796
-        $isNew = (int)$redirectConfig['id'] === 0;
796
+        $isNew = (int) $redirectConfig[ 'id' ] === 0;
797 797
         $event = new RedirectEvent([
798 798
             'isNew' => $isNew,
799
-            'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'],
800
-            'destinationUrl' => $redirectConfig['redirectDestUrl'],
801
-            'matchType' => $redirectConfig['redirectSrcMatch'],
802
-            'redirectType' => $redirectConfig['redirectHttpCode'],
799
+            'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ],
800
+            'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ],
801
+            'matchType' => $redirectConfig[ 'redirectSrcMatch' ],
802
+            'redirectType' => $redirectConfig[ 'redirectHttpCode' ],
803 803
         ]);
804 804
         $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event);
805 805
         if (!$event->isValid) {
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
                 Craft::t(
812 812
                     'retour',
813 813
                     'Updating existing redirect: {redirect}',
814
-                    ['redirect' => print_r($redirectConfig, true)]
814
+                    [ 'redirect' => print_r($redirectConfig, true) ]
815 815
                 ),
816 816
                 __METHOD__
817 817
             );
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
                     '{{%retour_static_redirects}}',
822 822
                     $redirectConfig,
823 823
                     [
824
-                        'id' => $redirectConfig['id'],
824
+                        'id' => $redirectConfig[ 'id' ],
825 825
                     ]
826 826
                 )->execute();
827 827
             } catch (Exception $e) {
@@ -832,11 +832,11 @@  discard block
 block discarded – undo
832 832
                 Craft::t(
833 833
                     'retour',
834 834
                     'Creating new redirect: {redirect}',
835
-                    ['redirect' => print_r($redirectConfig, true)]
835
+                    [ 'redirect' => print_r($redirectConfig, true) ]
836 836
                 ),
837 837
                 __METHOD__
838 838
             );
839
-            unset($redirectConfig['id']);
839
+            unset($redirectConfig[ 'id' ]);
840 840
             // Create a new record
841 841
             try {
842 842
                 $db->createCommand()->insert(
@@ -849,15 +849,15 @@  discard block
 block discarded – undo
849 849
         }
850 850
         // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl
851 851
         $testRedirectConfig = $this->getRedirectByRedirectSrcUrl(
852
-            $redirectConfig['redirectDestUrl'],
853
-            $redirectConfig['siteId']
852
+            $redirectConfig[ 'redirectDestUrl' ],
853
+            $redirectConfig[ 'siteId' ]
854 854
         );
855 855
         if ($testRedirectConfig !== null) {
856 856
             Craft::debug(
857 857
                 Craft::t(
858 858
                     'retour',
859 859
                     'Deleting redirect to prevent a loop: {redirect}',
860
-                    ['redirect' => print_r($testRedirectConfig, true)]
860
+                    [ 'redirect' => print_r($testRedirectConfig, true) ]
861 861
                 ),
862 862
                 __METHOD__
863 863
             );
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
             try {
866 866
                 $db->createCommand()->delete(
867 867
                     '{{%retour_static_redirects}}',
868
-                    ['id' => $testRedirectConfig['id']]
868
+                    [ 'id' => $testRedirectConfig[ 'id' ] ]
869 869
                 )->execute();
870 870
             } catch (Exception $e) {
871 871
                 Craft::error($e->getMessage(), __METHOD__);
@@ -898,17 +898,17 @@  discard block
 block discarded – undo
898 898
      */
899 899
     public function excludeUri($uri): bool
900 900
     {
901
-        $uri = '/'.ltrim($uri, '/');
901
+        $uri = '/' . ltrim($uri, '/');
902 902
         if (!empty(Retour::$settings->excludePatterns)) {
903 903
             foreach (Retour::$settings->excludePatterns as $excludePattern) {
904
-                $pattern = '`'.$excludePattern['pattern'].'`i';
904
+                $pattern = '`' . $excludePattern[ 'pattern' ] . '`i';
905 905
                 try {
906 906
                     if (preg_match($pattern, $uri) === 1) {
907 907
                         return true;
908 908
                     }
909 909
                 } catch (\Exception $e) {
910 910
                     // That's fine
911
-                    Craft::error('Invalid exclude URI Regex: '.$pattern, __METHOD__);
911
+                    Craft::error('Invalid exclude URI Regex: ' . $pattern, __METHOD__);
912 912
                 }
913 913
             }
914 914
         }
Please login to merge, or discard this patch.
src/controllers/TablesController.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -206,7 +206,7 @@
 block discarded – undo
206 206
             ->orderBy([$sortField => $sortType])
207 207
             ->filterWhere(['like', 'redirectSrcUrl', $filter])
208 208
             ->orFilterWhere(['like', 'redirectDestUrl', $filter])
209
-           ;
209
+            ;
210 210
         if ((int)$siteId !== 0) {
211 211
             $query->andWhere(['siteId' => $siteId]);
212 212
         }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $handled = 'all'
97 97
     ): Response {
98 98
         PermissionHelper::controllerPermissionCheck('retour:dashboard');
99
-        $data = [];
99
+        $data = [ ];
100 100
         $sortField = 'hitCount';
101 101
         $sortType = 'DESC';
102 102
         // Figure out the sorting type
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
             }
109 109
         }
110 110
         $sortType = strtoupper($sortType);
111
-        $sortType = self::SORT_MAP[$sortType] ?? self::SORT_MAP['DESC'];
111
+        $sortType = self::SORT_MAP[ $sortType ] ?? self::SORT_MAP[ 'DESC' ];
112 112
         // Validate untrusted data
113 113
         if (!in_array($sortField, self::ALLOWED_STATS_SORT_FIELDS, true)) {
114 114
             throw new BadRequestHttpException(Craft::t('retour', 'Invalid sort field specified.'));
@@ -116,35 +116,35 @@  discard block
 block discarded – undo
116 116
         // Query the db table
117 117
         $offset = ($page - 1) * $per_page;
118 118
         $query = (new Query())
119
-            ->from(['{{%retour_stats}}'])
119
+            ->from([ '{{%retour_stats}}' ])
120 120
             ->offset($offset)
121 121
             ->limit($per_page)
122
-            ->orderBy([$sortField => $sortType])
123
-            ->filterWhere(['like', 'redirectSrcUrl', $filter])
124
-            ->orFilterWhere(['like', 'referrerUrl', $filter])
122
+            ->orderBy([ $sortField => $sortType ])
123
+            ->filterWhere([ 'like', 'redirectSrcUrl', $filter ])
124
+            ->orFilterWhere([ 'like', 'referrerUrl', $filter ])
125 125
             ;
126
-        if ((int)$siteId !== 0) {
127
-            $query->andWhere(['siteId' => $siteId]);
126
+        if ((int) $siteId !== 0) {
127
+            $query->andWhere([ 'siteId' => $siteId ]);
128 128
         }
129 129
         if ($handled !== 'all') {
130
-            $query->andWhere(['handledByRetour' => self::HANDLED_MAP[$handled]]);
130
+            $query->andWhere([ 'handledByRetour' => self::HANDLED_MAP[ $handled ] ]);
131 131
         }
132 132
         $stats = $query->all();
133 133
         if ($stats) {
134 134
             // Add in the `addLink` field
135 135
             foreach ($stats as &$stat) {
136
-                $stat['addLink'] = '';
137
-                if (!$stat['handledByRetour']) {
138
-                    $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/'));
139
-                    $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [
136
+                $stat[ 'addLink' ] = '';
137
+                if (!$stat[ 'handledByRetour' ]) {
138
+                    $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/'));
139
+                    $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [
140 140
                         'defaultUrl' => $encodedUrl
141 141
                     ]);
142 142
                 }
143 143
             }
144 144
             // Format the data for the API
145
-            $data['data'] = $stats;
145
+            $data[ 'data' ] = $stats;
146 146
             $count = $query->count();
147
-            $data['links']['pagination'] = [
147
+            $data[ 'links' ][ 'pagination' ] = [
148 148
                 'total' => $count,
149 149
                 'per_page' => $per_page,
150 150
                 'current_page' => $page,
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         $siteId = 0
181 181
     ): Response {
182 182
         PermissionHelper::controllerPermissionCheck('retour:redirects');
183
-        $data = [];
183
+        $data = [ ];
184 184
         $sortField = 'hitCount';
185 185
         $sortType = 'DESC';
186 186
         // Figure out the sorting type
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
             }
193 193
         }
194 194
         $sortType = strtoupper($sortType);
195
-        $sortType = self::SORT_MAP[$sortType] ?? self::SORT_MAP['DESC'];
195
+        $sortType = self::SORT_MAP[ $sortType ] ?? self::SORT_MAP[ 'DESC' ];
196 196
         // Validate untrusted data
197 197
         if (!in_array($sortField, self::ALLOWED_REDIRECTS_SORT_FIELDS, true)) {
198 198
             throw new BadRequestHttpException(Craft::t('retour', 'Invalid sort field specified.'));
@@ -200,42 +200,42 @@  discard block
 block discarded – undo
200 200
         // Query the db table
201 201
         $offset = ($page - 1) * $per_page;
202 202
         $query = (new Query())
203
-            ->from(['{{%retour_static_redirects}}'])
203
+            ->from([ '{{%retour_static_redirects}}' ])
204 204
             ->offset($offset)
205 205
             ->limit($per_page)
206
-            ->orderBy([$sortField => $sortType])
207
-            ->filterWhere(['like', 'redirectSrcUrl', $filter])
208
-            ->orFilterWhere(['like', 'redirectDestUrl', $filter])
206
+            ->orderBy([ $sortField => $sortType ])
207
+            ->filterWhere([ 'like', 'redirectSrcUrl', $filter ])
208
+            ->orFilterWhere([ 'like', 'redirectDestUrl', $filter ])
209 209
            ;
210
-        if ((int)$siteId !== 0) {
211
-            $query->andWhere(['siteId' => $siteId]);
210
+        if ((int) $siteId !== 0) {
211
+            $query->andWhere([ 'siteId' => $siteId ]);
212 212
         }
213 213
         $redirects = $query->all();
214 214
         // Add in the `deleteLink` field and clean up the redirects
215 215
         foreach ($redirects as &$redirect) {
216 216
             // Make sure the destination URL is not a regex
217
-            if ($redirect['redirectMatchType'] !== 'exactmatch') {
218
-                if (preg_match("/\$\d+/", $redirect['redirectDestUrl'])) {
219
-                    $redirect['redirectDestUrl'] = '';
217
+            if ($redirect[ 'redirectMatchType' ] !== 'exactmatch') {
218
+                if (preg_match("/\$\d+/", $redirect[ 'redirectDestUrl' ])) {
219
+                    $redirect[ 'redirectDestUrl' ] = '';
220 220
                 }
221 221
             }
222 222
             // Handle extracting the site name
223
-            $redirect['siteName'] = Craft::t('retour', 'All Sites');
224
-            if ($redirect['siteId']) {
223
+            $redirect[ 'siteName' ] = Craft::t('retour', 'All Sites');
224
+            if ($redirect[ 'siteId' ]) {
225 225
                 $sites = Craft::$app->getSites();
226
-                $site = $sites->getSiteById($redirect['siteId']);
226
+                $site = $sites->getSiteById($redirect[ 'siteId' ]);
227 227
                 if ($site) {
228
-                    $redirect['siteName'] = $site->name;
228
+                    $redirect[ 'siteName' ] = $site->name;
229 229
                 }
230 230
             }
231 231
 
232
-            $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']);
232
+            $redirect[ 'editLink' ] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]);
233 233
         }
234 234
         // Format the data for the API
235 235
         if ($redirects) {
236
-            $data['data'] = $redirects;
236
+            $data[ 'data' ] = $redirects;
237 237
             $count = $query->count();
238
-            $data['links']['pagination'] = [
238
+            $data[ 'links' ][ 'pagination' ] = [
239 239
                 'total' => $count,
240 240
                 'per_page' => $per_page,
241 241
                 'current_page' => $page,
Please login to merge, or discard this patch.
src/helpers/Manifest.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
             $bundle->sourcePath,
99 99
             true
100 100
         );
101
-        self::$config['server']['manifestPath'] = Craft::getAlias($bundle->sourcePath);
102
-        self::$config['server']['publicPath'] = $baseAssetsUrl;
101
+        self::$config[ 'server' ][ 'manifestPath' ] = Craft::getAlias($bundle->sourcePath);
102
+        self::$config[ 'server' ][ 'publicPath' ] = $baseAssetsUrl;
103 103
         $useDevServer = getenv('NYS_PLUGIN_DEVSERVER');
104 104
         if ($useDevServer !== false) {
105
-            self::$config['useDevServer'] = (bool)$useDevServer;
105
+            self::$config[ 'useDevServer' ] = (bool) $useDevServer;
106 106
         }
107 107
     }
108 108
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
     public static function registerJsModules(array $modules)
117 117
     {
118 118
         $view = Craft::$app->getView();
119
-        foreach($modules as $module) {
119
+        foreach ($modules as $module) {
120 120
             $jsModule = self::getModule(self::$config, $module, 'modern');
121 121
             if ($jsModule) {
122 122
                 $view->registerJsFile($jsModule, [
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
     public static function registerCssModules(array $modules)
137 137
     {
138 138
         $view = Craft::$app->getView();
139
-        foreach($modules as $module) {
139
+        foreach ($modules as $module) {
140 140
             $cssModule = self::getModule(self::$config, $module, 'legacy');
141 141
             if ($cssModule) {
142 142
                 $view->registerCssFile($cssModule, [
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
                 return '';
168 168
             }
169 169
         }
170
-        $lines = [];
170
+        $lines = [ ];
171 171
         if ($async) {
172
-            $lines[] = "<script type=\"module\" src=\"{$modernModule}\"></script>";
173
-            $lines[] = "<script nomodule src=\"{$legacyModule}\"></script>";
172
+            $lines[ ] = "<script type=\"module\" src=\"{$modernModule}\"></script>";
173
+            $lines[ ] = "<script nomodule src=\"{$legacyModule}\"></script>";
174 174
         } else {
175
-            $lines[] = "<script src=\"{$legacyModule}\"></script>";
175
+            $lines[ ] = "<script src=\"{$legacyModule}\"></script>";
176 176
         }
177 177
 
178 178
         return implode("\r\n", $lines);
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
         if ($legacyModule === null) {
194 194
             return '';
195 195
         }
196
-        $lines = [];
196
+        $lines = [ ];
197 197
         if ($async) {
198
-            $lines[] = "<link rel=\"preload\" href=\"{$legacyModule}\" as=\"style\" onload=\"this.onload=null;this.rel='stylesheet'\" />";
199
-            $lines[] = "<noscript><link rel=\"stylesheet\" href=\"{$legacyModule}\"></noscript>";
198
+            $lines[ ] = "<link rel=\"preload\" href=\"{$legacyModule}\" as=\"style\" onload=\"this.onload=null;this.rel='stylesheet'\" />";
199
+            $lines[ ] = "<noscript><link rel=\"stylesheet\" href=\"{$legacyModule}\"></noscript>";
200 200
         } else {
201
-            $lines[] = "<link rel=\"stylesheet\" href=\"{$legacyModule}\" />";
201
+            $lines[ ] = "<link rel=\"stylesheet\" href=\"{$legacyModule}\" />";
202 202
         }
203 203
 
204 204
         return implode("\r\n", $lines);
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
         $module = self::getModuleEntry($config, $moduleName, $type, $soft);
225 225
         if ($module !== null) {
226 226
             $prefix = self::$isHot
227
-                ? $config['devServer']['publicPath']
228
-                : $config['server']['publicPath'];
227
+                ? $config[ 'devServer' ][ 'publicPath' ]
228
+                : $config[ 'server' ][ 'publicPath' ];
229 229
             // If the module isn't a full URL, prefix it
230 230
             if (!UrlHelper::isAbsoluteUrl($module)) {
231 231
                 $module = self::combinePaths($prefix, $module);
@@ -266,19 +266,19 @@  discard block
 block discarded – undo
266 266
         $manifest = self::getManifestFile($config, $type);
267 267
         if ($manifest !== null) {
268 268
             // Make sure it exists in the manifest
269
-            if (empty($manifest[$moduleName])) {
269
+            if (empty($manifest[ $moduleName ])) {
270 270
                 // Don't report errors for any files in SUPPRESS_ERRORS_FOR_MODULES
271 271
                 if (!in_array($moduleName, self::SUPPRESS_ERRORS_FOR_MODULES)) {
272 272
                     self::reportError(Craft::t(
273 273
                         'retour',
274 274
                         'Module does not exist in the manifest: {moduleName}',
275
-                        ['moduleName' => $moduleName]
275
+                        [ 'moduleName' => $moduleName ]
276 276
                     ), $soft);
277 277
                 }
278 278
 
279 279
                 return null;
280 280
             }
281
-            $module = $manifest[$moduleName];
281
+            $module = $manifest[ $moduleName ];
282 282
         }
283 283
 
284 284
         return $module;
@@ -298,14 +298,14 @@  discard block
 block discarded – undo
298 298
         $manifest = null;
299 299
         // Determine whether we should use the devServer for HMR or not
300 300
         $devMode = Craft::$app->getConfig()->getGeneral()->devMode;
301
-        self::$isHot = ($devMode && $config['useDevServer']);
301
+        self::$isHot = ($devMode && $config[ 'useDevServer' ]);
302 302
         // Try to get the manifest
303 303
         while ($manifest === null) {
304 304
             $manifestPath = self::$isHot
305
-                ? $config['devServer']['manifestPath']
306
-                : $config['server']['manifestPath'];
305
+                ? $config[ 'devServer' ][ 'manifestPath' ]
306
+                : $config[ 'server' ][ 'manifestPath' ];
307 307
             // Normalize the path
308
-            $path = self::combinePaths($manifestPath, $config['manifest'][$type]);
308
+            $path = self::combinePaths($manifestPath, $config[ 'manifest' ][ $type ]);
309 309
             $manifest = self::getJsonFile($path);
310 310
             // If the manifest isn't found, and it was hot, fall back on non-hot
311 311
             if ($manifest === null) {
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
                 self::reportError(Craft::t(
314 314
                     'retour',
315 315
                     'Manifest file not found at: {manifestPath}',
316
-                    ['manifestPath' => $manifestPath]
316
+                    [ 'manifestPath' => $manifestPath ]
317 317
                 ), true);
318 318
                 if (self::$isHot) {
319 319
                     // Try again, but not with home module replacement
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
      */
338 338
     protected static function getJsonFile(string $path)
339 339
     {
340
-        return self::getFileFromUri($path, [JsonHelper::class, 'decodeIfJson']);
340
+        return self::getFileFromUri($path, [ JsonHelper::class, 'decodeIfJson' ]);
341 341
     }
342 342
 
343 343
     /**
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
         // Resolve any aliases
364 364
         $alias = Craft::getAlias($path, false);
365 365
         if ($alias) {
366
-            $path = (string)$alias;
366
+            $path = (string) $alias;
367 367
         }
368 368
         // Make sure it's a full URL
369 369
         if (!UrlHelper::isAbsoluteUrl($path) && !is_file($path)) {
@@ -388,14 +388,14 @@  discard block
 block discarded – undo
388 388
     protected static function getFileContents(string $path, callable $callback = null)
389 389
     {
390 390
         // Return the memoized manifest if it exists
391
-        if (!empty(self::$files[$path])) {
392
-            return self::$files[$path];
391
+        if (!empty(self::$files[ $path ])) {
392
+            return self::$files[ $path ];
393 393
         }
394 394
         // Create the dependency tags
395 395
         $dependency = new TagDependency([
396 396
             'tags' => [
397 397
                 self::CACHE_TAG,
398
-                self::CACHE_TAG.$path,
398
+                self::CACHE_TAG . $path,
399 399
             ],
400 400
         ]);
401 401
         // Set the cache duration based on devMode
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
         // Get the result from the cache, or parse the file
406 406
         $cache = Craft::$app->getCache();
407 407
         $file = $cache->getOrSet(
408
-            self::CACHE_KEY.$path,
409
-            function () use ($path, $callback) {
408
+            self::CACHE_KEY . $path,
409
+            function() use ($path, $callback) {
410 410
                 $result = null;
411 411
                 $contents = @file_get_contents($path);
412 412
                 if ($contents) {
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
             $cacheDuration,
422 422
             $dependency
423 423
         );
424
-        self::$files[$path] = $file;
424
+        self::$files[ $path ] = $file;
425 425
 
426 426
         return $file;
427 427
     }
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
     protected static function combinePaths(string ...$paths): string
437 437
     {
438 438
         $last_key = count($paths) - 1;
439
-        array_walk($paths, function (&$val, $key) use ($last_key) {
439
+        array_walk($paths, function(&$val, $key) use ($last_key) {
440 440
             switch ($key) {
441 441
                 case 0:
442 442
                     $val = rtrim($val, '/ ');
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
         $last = array_pop($paths);
455 455
         $paths = array_filter($paths);
456 456
         array_unshift($paths, $first);
457
-        $paths[] = $last;
457
+        $paths[ ] = $last;
458 458
 
459 459
         return implode('/', $paths);
460 460
     }
Please login to merge, or discard this patch.