Passed
Push — develop ( 8e5692...189764 )
by Andrew
06:56 queued 02:13
created
src/models/StaticRedirects.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -96,18 +96,18 @@  discard block
 block discarded – undo
96 96
     public function rules()
97 97
     {
98 98
         return [
99
-            ['id', 'integer'],
100
-            ['siteId', 'integer'],
101
-            ['siteId', 'default', 'value' => null],
102
-            ['associatedElementId', 'default', 'value' => 0],
103
-            ['associatedElementId', 'integer'],
104
-            ['enabled', 'boolean'],
105
-            ['redirectSrcMatch', 'default', 'value' => 'pathonly'],
106
-            ['redirectSrcMatch', DbStringValidator::class, 'max' => 32],
107
-            ['redirectSrcMatch', 'string'],
108
-            ['redirectMatchType', 'default', 'value' => 'exactmatch'],
109
-            ['redirectMatchType', DbStringValidator::class, 'max' => 32],
110
-            ['redirectMatchType', 'string'],
99
+            [ 'id', 'integer' ],
100
+            [ 'siteId', 'integer' ],
101
+            [ 'siteId', 'default', 'value' => null ],
102
+            [ 'associatedElementId', 'default', 'value' => 0 ],
103
+            [ 'associatedElementId', 'integer' ],
104
+            [ 'enabled', 'boolean' ],
105
+            [ 'redirectSrcMatch', 'default', 'value' => 'pathonly' ],
106
+            [ 'redirectSrcMatch', DbStringValidator::class, 'max' => 32 ],
107
+            [ 'redirectSrcMatch', 'string' ],
108
+            [ 'redirectMatchType', 'default', 'value' => 'exactmatch' ],
109
+            [ 'redirectMatchType', DbStringValidator::class, 'max' => 32 ],
110
+            [ 'redirectMatchType', 'string' ],
111 111
             [
112 112
                 [
113 113
                     'redirectSrcUrl',
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 'default',
118 118
                 'value' => ''
119 119
             ],
120
-            ['redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl'],
120
+            [ 'redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl' ],
121 121
             [
122 122
                 [
123 123
                     'redirectSrcUrl',
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
                 ],
145 145
                 'string'
146 146
             ],
147
-            ['redirectHttpCode', 'integer'],
148
-            ['redirectHttpCode', 'default', 'value' => 301],
149
-            ['hitCount', 'default', 'value' => 0],
150
-            ['hitCount', 'integer'],
151
-            ['hitLastTime', 'safe'],
147
+            [ 'redirectHttpCode', 'integer' ],
148
+            [ 'redirectHttpCode', 'default', 'value' => 301 ],
149
+            [ 'hitCount', 'default', 'value' => 0 ],
150
+            [ 'hitCount', 'integer' ],
151
+            [ 'hitLastTime', 'safe' ],
152 152
         ];
153 153
     }
154 154
 
Please login to merge, or discard this patch.
src/controllers/ChartsController.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     public function actionDashboard(string $range = 'day', int $siteId = 0): Response
56 56
     {
57 57
         PermissionHelper::controllerPermissionCheck('retour:dashboard');
58
-        $data = [];
58
+        $data = [ ];
59 59
         $days = 1;
60 60
         switch ($range) {
61 61
             case 'day':
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
                     'COUNT(handledByRetour = 1 or null) as handled_cnt',
82 82
                 ])
83 83
                 ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )");
84
-            if ((int)$siteId !== 0) {
85
-                $query->andWhere(['siteId' => $siteId]);
84
+            if ((int) $siteId !== 0) {
85
+                $query->andWhere([ 'siteId' => $siteId ]);
86 86
             }
87 87
             $query
88 88
                 ->orderBy('date_formatted ASC')
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
                     "COUNT(CASE WHEN \"handledByRetour\" = true THEN 1 END) as handled_cnt",
100 100
                 ])
101 101
                 ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )");
102
-            if ((int)$siteId !== 0) {
103
-                $query->andWhere(['siteId' => $siteId]);
102
+            if ((int) $siteId !== 0) {
103
+                $query->andWhere([ 'siteId' => $siteId ]);
104 104
             }
105 105
             $query
106 106
                 ->orderBy('date_formatted ASC')
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
             $stats = $query->all();
109 109
         }
110 110
         if ($stats) {
111
-            $data[] = [
111
+            $data[ ] = [
112 112
                 'name' => '404 hits',
113
-                'data' => array_merge(['0'], ArrayHelper::getColumn($stats, 'cnt')),
114
-                'labels' => array_merge(['-'], ArrayHelper::getColumn($stats, 'date_formatted')),
113
+                'data' => array_merge([ '0' ], ArrayHelper::getColumn($stats, 'cnt')),
114
+                'labels' => array_merge([ '-' ], ArrayHelper::getColumn($stats, 'date_formatted')),
115 115
             ];
116
-            $data[] = [
116
+            $data[ ] = [
117 117
                 'name' => 'Handled 404 hits',
118
-                'data' => array_merge(['0'], ArrayHelper::getColumn($stats, 'handled_cnt')),
119
-                'labels' => array_merge(['-'], ArrayHelper::getColumn($stats, 'date_formatted')),
118
+                'data' => array_merge([ '0' ], ArrayHelper::getColumn($stats, 'handled_cnt')),
119
+                'labels' => array_merge([ '-' ], ArrayHelper::getColumn($stats, 'date_formatted')),
120 120
             ];
121 121
         }
122 122
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function actionWidget($days = 1): Response
134 134
     {
135
-        $data = [];
135
+        $data = [ ];
136 136
         // Different dbs do it different ways
137 137
         $stats = null;
138 138
         $handledStats = null;
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
         }
164 164
         if ($stats) {
165 165
             $data = [
166
-                (int)$stats,
167
-                (int)$handledStats,
166
+                (int) $stats,
167
+                (int) $handledStats,
168 168
             ];
169 169
         }
170 170
 
Please login to merge, or discard this patch.
src/controllers/FileController.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     // Protected Properties
74 74
     // =========================================================================
75 75
 
76
-    protected $allowAnonymous = [];
76
+    protected $allowAnonymous = [ ];
77 77
 
78 78
     // Public Methods
79 79
     // =========================================================================
@@ -98,20 +98,20 @@  discard block
 block discarded – undo
98 98
         $headers = array_flip($csv->fetchOne(0));
99 99
         $csv->setOffset(1);
100 100
         $columns = ArrayHelper::filterEmptyStringsFromArray($columns);
101
-        $csv->each(function ($row) use ($headers, $columns) {
101
+        $csv->each(function($row) use ($headers, $columns) {
102 102
             $redirectConfig = [
103 103
                 'id' => 0,
104 104
             ];
105 105
             $index = 0;
106 106
             foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) {
107
-                if (isset($columns[$index], $headers[$columns[$index]])) {
108
-                    $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]])
107
+                if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) {
108
+                    $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ])
109 109
                         ? null
110
-                        : $row[$headers[$columns[$index]]];
110
+                        : $row[ $headers[ $columns[ $index ] ] ];
111 111
                 }
112 112
                 $index++;
113 113
             }
114
-            Craft::debug('Importing row: '.print_r($redirectConfig, true), __METHOD__);
114
+            Craft::debug('Importing row: ' . print_r($redirectConfig, true), __METHOD__);
115 115
             Retour::$plugin->redirects->saveRedirect($redirectConfig);
116 116
 
117 117
             return true;
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      */
134 134
     public function actionImportCsv(string $siteHandle = null): Response
135 135
     {
136
-        $variables = [];
136
+        $variables = [ ];
137 137
         PermissionHelper::controllerPermissionCheck('retour:redirects');
138 138
         // If your CSV document was created or is read on a Macintosh computer,
139 139
         // add the following lines before using the library to help PHP detect line ending in Mac OS X
@@ -151,43 +151,43 @@  discard block
 block discarded – undo
151 151
         } catch (InvalidConfigException $e) {
152 152
             Craft::error($e->getMessage(), __METHOD__);
153 153
         }
154
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
154
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
155 155
             '@nystudio107/retour/assetbundles/retour/dist',
156 156
             true
157 157
         );
158 158
         // Enabled sites
159 159
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
160
-        $variables['controllerHandle'] = 'file';
160
+        $variables[ 'controllerHandle' ] = 'file';
161 161
 
162 162
         // Basic variables
163
-        $variables['fullPageForm'] = true;
164
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
165
-        $variables['pluginName'] = $pluginName;
166
-        $variables['title'] = $templateTitle;
167
-        $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : '';
168
-        $variables['crumbs'] = [
163
+        $variables[ 'fullPageForm' ] = true;
164
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
165
+        $variables[ 'pluginName' ] = $pluginName;
166
+        $variables[ 'title' ] = $templateTitle;
167
+        $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : '';
168
+        $variables[ 'crumbs' ] = [
169 169
             [
170 170
                 'label' => $pluginName,
171 171
                 'url' => UrlHelper::cpUrl('retour'),
172 172
             ],
173 173
             [
174 174
                 'label' => 'Redirects',
175
-                'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri),
175
+                'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri),
176 176
             ],
177 177
         ];
178
-        $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}";
179
-        $variables['selectedSubnavItem'] = 'redirects';
178
+        $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}";
179
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
180 180
 
181 181
         // The CSV file
182 182
         $file = UploadedFile::getInstanceByName('file');
183 183
         if ($file !== null) {
184
-            $filename = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.uniqid($file->name, true);
184
+            $filename = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . uniqid($file->name, true);
185 185
             $file->saveAs($filename, false);
186 186
             $csv = Reader::createFromPath($file->tempName);
187 187
             $headers = $csv->fetchOne(0);
188 188
             Craft::info(print_r($headers, true), __METHOD__);
189
-            $variables['headers'] = $headers;
190
-            $variables['filename'] = $filename;
189
+            $variables[ 'headers' ] = $headers;
190
+            $variables[ 'filename' ] = $filename;
191 191
         }
192 192
 
193 193
         // Render the template
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         }
234 234
         // Query the db table
235 235
         $data = (new Query())
236
-            ->from([$table])
236
+            ->from([ $table ])
237 237
             ->select(array_keys($columns))
238 238
             ->orderBy('hitCount DESC')
239 239
             ->all();
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         $csv = Writer::createFromFileObject(new \SplTempFileObject());
242 242
         $csv->insertOne(array_values($columns));
243 243
         $csv->insertAll($data);
244
-        $csv->output($filename.'.csv');
244
+        $csv->output($filename . '.csv');
245 245
         exit(0);
246 246
     }
247 247
 }
Please login to merge, or discard this patch.
src/Retour.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     /**
100 100
      * @var array The URIs for the element before it was saved
101 101
      */
102
-    public $oldElementUris = [];
102
+    public $oldElementUris = [ ];
103 103
 
104 104
     // Public Methods
105 105
     // =========================================================================
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             Craft::t(
131 131
                 'retour',
132 132
                 '{name} plugin loaded',
133
-                ['name' => $this->name]
133
+                [ 'name' => $this->name ]
134 134
             ),
135 135
             __METHOD__
136 136
         );
@@ -150,18 +150,18 @@  discard block
 block discarded – undo
150 150
      */
151 151
     public function getCpNavItem()
152 152
     {
153
-        $subNavs = [];
153
+        $subNavs = [ ];
154 154
         $navItem = parent::getCpNavItem();
155 155
         $currentUser = Craft::$app->getUser()->getIdentity();
156 156
         // Only show sub-navs the user has permission to view
157 157
         if ($currentUser->can('retour:dashboard')) {
158
-            $subNavs['dashboard'] = [
158
+            $subNavs[ 'dashboard' ] = [
159 159
                 'label' => 'Dashboard',
160 160
                 'url' => 'retour/dashboard',
161 161
             ];
162 162
         }
163 163
         if ($currentUser->can('retour:redirects')) {
164
-            $subNavs['redirects'] = [
164
+            $subNavs[ 'redirects' ] = [
165 165
                 'label' => 'Redirects',
166 166
                 'url' => 'retour/redirects',
167 167
             ];
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
             $editableSettings = false;
173 173
         }
174 174
         if ($currentUser->can('retour:settings') && $editableSettings) {
175
-            $subNavs['settings'] = [
175
+            $subNavs[ 'settings' ] = [
176 176
                 'label' => 'Settings',
177 177
                 'url' => 'retour/settings',
178 178
             ];
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
         Event::on(
232 232
             ClearCaches::class,
233 233
             ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
234
-            function (RegisterCacheOptionsEvent $event) {
234
+            function(RegisterCacheOptionsEvent $event) {
235 235
                 Craft::debug(
236 236
                     'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS',
237 237
                     __METHOD__
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         Event::on(
248 248
             Plugins::class,
249 249
             Plugins::EVENT_AFTER_INSTALL_PLUGIN,
250
-            function (PluginEvent $event) {
250
+            function(PluginEvent $event) {
251 251
                 if ($event->plugin === $this) {
252 252
                     // Invalidate our caches after we've been installed
253 253
                     $this->clearAllCaches();
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
         Event::on(
275 275
             CraftVariable::class,
276 276
             CraftVariable::EVENT_INIT,
277
-            function (Event $event) {
277
+            function(Event $event) {
278 278
                 /** @var CraftVariable $variable */
279 279
                 $variable = $event->sender;
280 280
                 $variable->set('retour', RetourVariable::class);
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
         Event::on(
285 285
             Elements::class,
286 286
             Elements::EVENT_BEFORE_SAVE_ELEMENT,
287
-            function (ElementEvent $event) {
287
+            function(ElementEvent $event) {
288 288
                 Craft::debug(
289 289
                     'Elements::EVENT_BEFORE_SAVE_ELEMENT',
290 290
                     __METHOD__
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
                         if ($oldElement !== null) {
300 300
                             // Stash the old URLs by element id, and do so only once,
301 301
                             // in case we are called more than once per request
302
-                            if (empty($this->oldElementUris[$oldElement->id])) {
303
-                                $this->oldElementUris[$oldElement->id] = $this->getAllElementUris($oldElement);
302
+                            if (empty($this->oldElementUris[ $oldElement->id ])) {
303
+                                $this->oldElementUris[ $oldElement->id ] = $this->getAllElementUris($oldElement);
304 304
                             }
305 305
                         }
306 306
                     }
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         Event::on(
312 312
             Elements::class,
313 313
             Elements::EVENT_AFTER_SAVE_ELEMENT,
314
-            function (ElementEvent $event) {
314
+            function(ElementEvent $event) {
315 315
                 Craft::debug(
316 316
                     'Elements::EVENT_AFTER_SAVE_ELEMENT',
317 317
                     __METHOD__
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         Event::on(
328 328
             Plugins::class,
329 329
             Plugins::EVENT_AFTER_LOAD_PLUGINS,
330
-            function () {
330
+            function() {
331 331
                 // Install these only after all other plugins have loaded
332 332
                 $request = Craft::$app->getRequest();
333 333
                 // Only respond to non-console site requests
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
         Event::on(
352 352
             UrlManager::class,
353 353
             UrlManager::EVENT_REGISTER_SITE_URL_RULES,
354
-            function (RegisterUrlRulesEvent $event) {
354
+            function(RegisterUrlRulesEvent $event) {
355 355
                 Craft::debug(
356 356
                     'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
357 357
                     __METHOD__
@@ -374,15 +374,15 @@  discard block
 block discarded – undo
374 374
         Event::on(
375 375
             Dashboard::class,
376 376
             Dashboard::EVENT_REGISTER_WIDGET_TYPES,
377
-            function (RegisterComponentTypesEvent $event) {
378
-                $event->types[] = RetourWidget::class;
377
+            function(RegisterComponentTypesEvent $event) {
378
+                $event->types[ ] = RetourWidget::class;
379 379
             }
380 380
         );
381 381
         // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES
382 382
         Event::on(
383 383
             UrlManager::class,
384 384
             UrlManager::EVENT_REGISTER_CP_URL_RULES,
385
-            function (RegisterUrlRulesEvent $event) {
385
+            function(RegisterUrlRulesEvent $event) {
386 386
                 Craft::debug(
387 387
                     'UrlManager::EVENT_REGISTER_CP_URL_RULES',
388 388
                     __METHOD__
@@ -398,13 +398,13 @@  discard block
 block discarded – undo
398 398
         Event::on(
399 399
             UserPermissions::class,
400 400
             UserPermissions::EVENT_REGISTER_PERMISSIONS,
401
-            function (RegisterUserPermissionsEvent $event) {
401
+            function(RegisterUserPermissionsEvent $event) {
402 402
                 Craft::debug(
403 403
                     'UserPermissions::EVENT_REGISTER_PERMISSIONS',
404 404
                     __METHOD__
405 405
                 );
406 406
                 // Register our custom permissions
407
-                $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions();
407
+                $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions();
408 408
             }
409 409
         );
410 410
     }
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
         Event::on(
421 421
             ErrorHandler::class,
422 422
             ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
423
-            function (ExceptionEvent $event) {
423
+            function(ExceptionEvent $event) {
424 424
                 Craft::debug(
425 425
                     'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION',
426 426
                     __METHOD__
@@ -463,16 +463,16 @@  discard block
 block discarded – undo
463 463
     protected function handleElementUriChange(Element $element)
464 464
     {
465 465
         $uris = $this->getAllElementUris($element);
466
-        if (!empty($this->oldElementUris[$element->id])) {
467
-            $oldElementUris = $this->oldElementUris[$element->id];
466
+        if (!empty($this->oldElementUris[ $element->id ])) {
467
+            $oldElementUris = $this->oldElementUris[ $element->id ];
468 468
             foreach ($uris as $siteId => $newUri) {
469
-                if (!empty($oldElementUris[$siteId])) {
470
-                    $oldUri = $oldElementUris[$siteId];
469
+                if (!empty($oldElementUris[ $siteId ])) {
470
+                    $oldUri = $oldElementUris[ $siteId ];
471 471
                     Craft::debug(
472 472
                         Craft::t(
473 473
                             'retour',
474 474
                             'Comparing old: {oldUri} to new: {newUri}',
475
-                            ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)]
475
+                            [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ]
476 476
                         ),
477 477
                         __METHOD__
478 478
                     );
@@ -507,12 +507,12 @@  discard block
 block discarded – undo
507 507
      */
508 508
     protected function getAllElementUris(Element $element): array
509 509
     {
510
-        $uris = [];
510
+        $uris = [ ];
511 511
         $sites = Craft::$app->getSites()->getAllSites();
512 512
         foreach ($sites as $site) {
513 513
             $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id);
514 514
             if ($uri !== null) {
515
-                $uris[$site->id] = $uri;
515
+                $uris[ $site->id ] = $uri;
516 516
             }
517 517
         }
518 518
 
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
             Craft::t(
521 521
                 'retour',
522 522
                 'Getting Element URIs: {uris}',
523
-                ['uris' => print_r($uris, true)]
523
+                [ 'uris' => print_r($uris, true) ]
524 524
             ),
525 525
             __METHOD__
526 526
         );
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
             [
585 585
                 'key' => 'retour-redirect-caches',
586 586
                 'label' => Craft::t('retour', 'Retour redirect caches'),
587
-                'action' => [self::$plugin->redirects, 'invalidateCaches'],
587
+                'action' => [ self::$plugin->redirects, 'invalidateCaches' ],
588 588
             ],
589 589
         ];
590 590
     }
Please login to merge, or discard this patch.
src/controllers/TablesController.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $siteId = 0
63 63
     ): Response {
64 64
         PermissionHelper::controllerPermissionCheck('retour:dashboard');
65
-        $data = [];
65
+        $data = [ ];
66 66
         $sortField = 'hitCount';
67 67
         $sortType = 'DESC';
68 68
         // Figure out the sorting type
@@ -76,42 +76,42 @@  discard block
 block discarded – undo
76 76
         // Query the db table
77 77
         $offset = ($page - 1) * $per_page;
78 78
         $query = (new Query())
79
-            ->from(['{{%retour_stats}}'])
79
+            ->from([ '{{%retour_stats}}' ])
80 80
             ->offset($offset)
81 81
             ->limit($per_page)
82 82
             ->orderBy("{$sortField} {$sortType}");
83
-        if ((int)$siteId !== 0) {
84
-            $query->where(['siteId' => $siteId]);
83
+        if ((int) $siteId !== 0) {
84
+            $query->where([ 'siteId' => $siteId ]);
85 85
         }
86 86
         if ($filter !== '') {
87
-            $query->where(['like', 'redirectSrcUrl', $filter]);
88
-            $query->orWhere(['like', 'referrerUrl', $filter]);
87
+            $query->where([ 'like', 'redirectSrcUrl', $filter ]);
88
+            $query->orWhere([ 'like', 'referrerUrl', $filter ]);
89 89
         }
90 90
         $stats = $query->all();
91 91
         if ($stats) {
92 92
             // Add in the `addLink` field
93 93
             foreach ($stats as &$stat) {
94
-                $stat['addLink'] = '';
95
-                if (!$stat['handledByRetour']) {
96
-                    $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/'));
97
-                    $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [
94
+                $stat[ 'addLink' ] = '';
95
+                if (!$stat[ 'handledByRetour' ]) {
96
+                    $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/'));
97
+                    $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [
98 98
                         'defaultUrl' => $encodedUrl
99 99
                     ]);
100 100
                 }
101 101
             }
102 102
             // Format the data for the API
103
-            $data['data'] = $stats;
103
+            $data[ 'data' ] = $stats;
104 104
             $query = (new Query())
105
-                ->from(['{{%retour_stats}}']);
106
-            if ((int)$siteId !== 0) {
107
-                $query->where(['siteId' => $siteId]);
105
+                ->from([ '{{%retour_stats}}' ]);
106
+            if ((int) $siteId !== 0) {
107
+                $query->where([ 'siteId' => $siteId ]);
108 108
             }
109 109
             if ($filter !== '') {
110
-                $query->where(['like', 'redirectSrcUrl', $filter]);
111
-                $query->orWhere(['like', 'referrerUrl', $filter]);
110
+                $query->where([ 'like', 'redirectSrcUrl', $filter ]);
111
+                $query->orWhere([ 'like', 'referrerUrl', $filter ]);
112 112
             }
113 113
             $count = $query->count();
114
-            $data['links']['pagination'] = [
114
+            $data[ 'links' ][ 'pagination' ] = [
115 115
                 'total' => $count,
116 116
                 'per_page' => $per_page,
117 117
                 'current_page' => $page,
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         $siteId = 0
147 147
     ): Response {
148 148
         PermissionHelper::controllerPermissionCheck('retour:redirects');
149
-        $data = [];
149
+        $data = [ ];
150 150
         $sortField = 'hitCount';
151 151
         $sortType = 'DESC';
152 152
         // Figure out the sorting type
@@ -160,43 +160,43 @@  discard block
 block discarded – undo
160 160
         // Query the db table
161 161
         $offset = ($page - 1) * $per_page;
162 162
         $query = (new Query())
163
-            ->from(['{{%retour_static_redirects}}'])
163
+            ->from([ '{{%retour_static_redirects}}' ])
164 164
             ->offset($offset)
165 165
             ->limit($per_page)
166 166
             ->orderBy("{$sortField} {$sortType}");
167
-        if ((int)$siteId !== 0) {
168
-            $query->where(['siteId' => $siteId]);
167
+        if ((int) $siteId !== 0) {
168
+            $query->where([ 'siteId' => $siteId ]);
169 169
         }
170 170
         if ($filter !== '') {
171
-            $query->where(['like', 'redirectSrcUrl', $filter]);
172
-            $query->orWhere(['like', 'redirectDestUrl', $filter]);
171
+            $query->where([ 'like', 'redirectSrcUrl', $filter ]);
172
+            $query->orWhere([ 'like', 'redirectDestUrl', $filter ]);
173 173
         }
174 174
         $redirects = $query->all();
175 175
         // Add in the `deleteLink` field and clean up the redirects
176 176
         foreach ($redirects as &$redirect) {
177 177
             // Make sure the destination URL is not a regex
178
-            if ($redirect['redirectMatchType'] !== 'exactmatch') {
179
-                if (preg_match("/\$\d+/", $redirect['redirectDestUrl'])) {
180
-                    $redirect['redirectDestUrl'] = '';
178
+            if ($redirect[ 'redirectMatchType' ] !== 'exactmatch') {
179
+                if (preg_match("/\$\d+/", $redirect[ 'redirectDestUrl' ])) {
180
+                    $redirect[ 'redirectDestUrl' ] = '';
181 181
                 }
182 182
             }
183
-            $redirect['deleteLink'] = UrlHelper::cpUrl('retour/delete-redirect/'.$redirect['id']);
184
-            $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']);
183
+            $redirect[ 'deleteLink' ] = UrlHelper::cpUrl('retour/delete-redirect/' . $redirect[ 'id' ]);
184
+            $redirect[ 'editLink' ] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]);
185 185
         }
186 186
         // Format the data for the API
187 187
         if ($redirects) {
188
-            $data['data'] = $redirects;
188
+            $data[ 'data' ] = $redirects;
189 189
             $query = (new Query())
190
-                ->from(['{{%retour_static_redirects}}']);
191
-            if ((int)$siteId !== 0) {
192
-                $query->where(['siteId' => $siteId]);
190
+                ->from([ '{{%retour_static_redirects}}' ]);
191
+            if ((int) $siteId !== 0) {
192
+                $query->where([ 'siteId' => $siteId ]);
193 193
             }
194 194
             if ($filter !== '') {
195
-                $query->where(['like', 'redirectSrcUrl', $filter]);
196
-                $query->orWhere(['like', 'redirectDestUrl', $filter]);
195
+                $query->where([ 'like', 'redirectSrcUrl', $filter ]);
196
+                $query->orWhere([ 'like', 'redirectDestUrl', $filter ]);
197 197
             }
198 198
             $count = $query->count();
199
-            $data['links']['pagination'] = [
199
+            $data[ 'links' ][ 'pagination' ] = [
200 200
                 'total' => $count,
201 201
                 'per_page' => $per_page,
202 202
                 'current_page' => $page,
Please login to merge, or discard this patch.
src/services/Statistics.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         }
59 59
         // Query the db table
60 60
         $stats = (new Query())
61
-            ->from(['{{%retour_stats}}'])
61
+            ->from([ '{{%retour_stats}}' ])
62 62
             ->orderBy('hitCount DESC')
63 63
             ->limit(Retour::$settings->statsDisplayLimit)
64 64
             ->all();
@@ -77,13 +77,13 @@  discard block
 block discarded – undo
77 77
     public function getRecentStatistics($days = 1, $handled = false): array
78 78
     {
79 79
         // Ensure is an int
80
-        $handledInt = (int)$handled;
81
-        $stats = [];
80
+        $handledInt = (int) $handled;
81
+        $stats = [ ];
82 82
         $db = Craft::$app->getDb();
83 83
         if ($db->getIsMysql()) {
84 84
             // Query the db table
85 85
             $stats = (new Query())
86
-                ->from(['{{%retour_stats}}'])
86
+                ->from([ '{{%retour_stats}}' ])
87 87
                 ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )")
88 88
                 ->andWhere("handledByRetour = {$handledInt}")
89 89
                 ->orderBy('hitLastTime DESC')
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
         if ($db->getIsPgsql()) {
93 93
             // Query the db table
94 94
             $stats = (new Query())
95
-                ->from(['{{%retour_stats}}'])
95
+                ->from([ '{{%retour_stats}}' ])
96 96
                 ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )")
97
-                ->andWhere(['handledByRetour' => $handledInt])
97
+                ->andWhere([ 'handledByRetour' => $handledInt ])
98 98
                 ->orderBy('hitLastTime DESC')
99 99
                 ->all();
100 100
         }
@@ -161,16 +161,16 @@  discard block
 block discarded – undo
161 161
         $stats->validate();
162 162
         // Find any existing retour_stats record
163 163
         $statsConfig = (new Query())
164
-            ->from(['{{%retour_stats}}'])
165
-            ->where(['redirectSrcUrl' => $stats->redirectSrcUrl])
164
+            ->from([ '{{%retour_stats}}' ])
165
+            ->where([ 'redirectSrcUrl' => $stats->redirectSrcUrl ])
166 166
             ->one();
167 167
         // If no record is found, initialize some values
168 168
         if ($statsConfig === null) {
169 169
             $stats->id = 0;
170 170
             $stats->hitCount = 0;
171 171
         } else {
172
-            $stats->id = $statsConfig['id'];
173
-            $stats->hitCount = $statsConfig['hitCount'];
172
+            $stats->id = $statsConfig[ 'id' ];
173
+            $stats->hitCount = $statsConfig[ 'hitCount' ];
174 174
         }
175 175
         // Merge in the updated info
176 176
         $stats->siteId = $siteId;
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
         $stats->userAgent = $userAgent;
180 180
         $stats->exceptionMessage = $exceptionMessage;
181 181
         $stats->exceptionFilePath = $exceptionFilePath;
182
-        $stats->exceptionFileLine = (int)$exceptionFileLine;
182
+        $stats->exceptionFileLine = (int) $exceptionFileLine;
183 183
         $stats->hitLastTime = Db::prepareDateForDb(new \DateTime());
184
-        $stats->handledByRetour = (int)$handled;
184
+        $stats->handledByRetour = (int) $handled;
185 185
         $stats->hitCount++;
186 186
         $statsConfig = $stats->getAttributes();
187 187
         // Record the updated statistics
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
                 Craft::t(
252 252
                     'retour',
253 253
                     'Trimmed {rows} from retour_stats table',
254
-                    ['rows' => $affectedRows]
254
+                    [ 'rows' => $affectedRows ]
255 255
                 ),
256 256
                 __METHOD__
257 257
             );
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                 Craft::t(
273 273
                     'retour',
274 274
                     'Error validating statistics {id}: {errors}',
275
-                    ['id' => $stats->id, 'errors' => print_r($stats->getErrors(), true)]
275
+                    [ 'id' => $stats->id, 'errors' => print_r($stats->getErrors(), true) ]
276 276
                 ),
277 277
                 __METHOD__
278 278
             );
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
         // Get the validated model attributes and save them to the db
283 283
         $statsConfig = $stats->getAttributes();
284 284
         $db = Craft::$app->getDb();
285
-        if ($statsConfig['id'] !== 0) {
285
+        if ($statsConfig[ 'id' ] !== 0) {
286 286
             // Update the existing record
287 287
             try {
288 288
                 $result = $db->createCommand()->update(
289 289
                     '{{%retour_stats}}',
290 290
                     $statsConfig,
291 291
                     [
292
-                        'id' => $statsConfig['id'],
292
+                        'id' => $statsConfig[ 'id' ],
293 293
                     ]
294 294
                 )->execute();
295 295
             } catch (Exception $e) {
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                 // Craft::error($e->getMessage(), __METHOD__);
299 299
             }
300 300
         } else {
301
-            unset($statsConfig['id']);
301
+            unset($statsConfig[ 'id' ]);
302 302
             // Create a new record
303 303
             try {
304 304
                 $db->createCommand()->insert(
Please login to merge, or discard this patch.
src/helpers/MultiSite.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     public static function setSitesMenuVariables(array &$variables)
37 37
     {
38 38
         // Set defaults based on the section settings
39
-        $variables['sitesMenu'] = [
39
+        $variables[ 'sitesMenu' ] = [
40 40
             0 => Craft::t(
41 41
                 'retour',
42 42
                 'All Sites'
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
             /** @var Site $site */
50 50
             foreach ($sites->getAllGroups() as $group) {
51 51
                 $groupSites = $sites->getSitesByGroupId($group->id);
52
-                $variables['sitesMenu'][$group->name]
53
-                    = ['optgroup' => $group->name];
52
+                $variables[ 'sitesMenu' ][ $group->name ]
53
+                    = [ 'optgroup' => $group->name ];
54 54
                 foreach ($groupSites as $groupSite) {
55 55
                     if (in_array($groupSite->id, $editableSites, false)) {
56
-                        $variables['sitesMenu'][$groupSite->id] = $groupSite->name;
56
+                        $variables[ 'sitesMenu' ][ $groupSite->id ] = $groupSite->name;
57 57
                     }
58 58
                 }
59 59
             }
@@ -73,53 +73,53 @@  discard block
 block discarded – undo
73 73
         $sites = Craft::$app->getSites();
74 74
         if (Craft::$app->getIsMultiSite()) {
75 75
             // Set defaults based on the section settings
76
-            $variables['enabledSiteIds'] = [];
77
-            $variables['siteIds'] = [];
76
+            $variables[ 'enabledSiteIds' ] = [ ];
77
+            $variables[ 'siteIds' ] = [ ];
78 78
 
79 79
             /** @var Site $site */
80 80
             foreach ($sites->getEditableSiteIds() as $editableSiteId) {
81
-                $variables['enabledSiteIds'][] = $editableSiteId;
82
-                $variables['siteIds'][] = $editableSiteId;
81
+                $variables[ 'enabledSiteIds' ][ ] = $editableSiteId;
82
+                $variables[ 'siteIds' ][ ] = $editableSiteId;
83 83
             }
84 84
 
85 85
             // Make sure the $siteId they are trying to edit is in our array of editable sites
86
-            if (!\in_array($siteId, $variables['enabledSiteIds'], false)) {
87
-                if (!empty($variables['enabledSiteIds'])) {
86
+            if (!\in_array($siteId, $variables[ 'enabledSiteIds' ], false)) {
87
+                if (!empty($variables[ 'enabledSiteIds' ])) {
88 88
                     if ($siteId !== 0) {
89
-                        $siteId = reset($variables['enabledSiteIds']);
89
+                        $siteId = reset($variables[ 'enabledSiteIds' ]);
90 90
                     }
91 91
                 } else {
92
-                    self::requirePermission('editSite:'.$siteId);
92
+                    self::requirePermission('editSite:' . $siteId);
93 93
                 }
94 94
             }
95 95
         }
96 96
         // Set the currentSiteId and currentSiteHandle
97
-        $variables['currentSiteId'] = empty($siteId) ? 0 : $siteId;
98
-        $variables['currentSiteHandle'] = empty($siteHandle)
97
+        $variables[ 'currentSiteId' ] = empty($siteId) ? 0 : $siteId;
98
+        $variables[ 'currentSiteHandle' ] = empty($siteHandle)
99 99
             ? Craft::$app->getSites()->currentSite->handle
100 100
             : $siteHandle;
101 101
 
102 102
         // Page title
103
-        $variables['showSites'] = (
103
+        $variables[ 'showSites' ] = (
104 104
             Craft::$app->getIsMultiSite() &&
105
-            \count($variables['enabledSiteIds'])
105
+            \count($variables[ 'enabledSiteIds' ])
106 106
         );
107 107
 
108
-        if ($variables['showSites']) {
109
-            if ($variables['currentSiteId'] === 0) {
110
-                $variables['sitesMenuLabel'] = Craft::t(
108
+        if ($variables[ 'showSites' ]) {
109
+            if ($variables[ 'currentSiteId' ] === 0) {
110
+                $variables[ 'sitesMenuLabel' ] = Craft::t(
111 111
                     'retour',
112 112
                     'All Sites'
113 113
                 );
114 114
             } else {
115
-                $variables['sitesMenuLabel'] = Craft::t(
115
+                $variables[ 'sitesMenuLabel' ] = Craft::t(
116 116
                     'site',
117
-                    $sites->getSiteById((int)$variables['currentSiteId'])->name
117
+                    $sites->getSiteById((int) $variables[ 'currentSiteId' ])->name
118 118
                 );
119 119
             }
120 120
         } else {
121
-            $variables['currentSiteId'] = 0;
122
-            $variables['sitesMenuLabel'] = '';
121
+            $variables[ 'currentSiteId' ] = 0;
122
+            $variables[ 'sitesMenuLabel' ] = '';
123 123
         }
124 124
     }
125 125
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         if ($siteHandle !== null) {
138 138
             $site = Craft::$app->getSites()->getSiteByHandle($siteHandle);
139 139
             if (!$site) {
140
-                throw new NotFoundHttpException('Invalid site handle: '.$siteHandle);
140
+                throw new NotFoundHttpException('Invalid site handle: ' . $siteHandle);
141 141
             }
142 142
             $siteId = $site->id;
143 143
         } else {
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
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
     // Whether the Statistics should be trimmed after each new statistic is recorded
46 46
     'automaticallyTrimStatistics' => true,
47 47
 
48
-     // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking
48
+        // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking
49 49
     'excludePatterns' => [
50 50
     ],
51 51
 ];
Please login to merge, or discard this patch.
src/services/Redirects.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                 Craft::t(
129 129
                     'retour',
130 130
                     '404 full URL: {fullUrl}, 404 path only: {pathOnly}',
131
-                    ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly]
131
+                    [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ]
132 132
                 ),
133 133
                 __METHOD__
134 134
             );
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
         $response = Craft::$app->getResponse();
163 163
         if ($redirect !== null) {
164 164
             // Figure out what type of source matching was done
165
-            $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly';
165
+            $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly';
166 166
             switch ($redirectSrcMatch) {
167 167
                 case 'pathonly':
168 168
                     $url = $pathOnly;
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
                     $url = $pathOnly;
175 175
                     break;
176 176
             }
177
-            $dest = $redirect['redirectDestUrl'];
177
+            $dest = $redirect[ 'redirectDestUrl' ];
178 178
             // If this isn't a full URL, make it one based on the appropriate site
179 179
             if (!UrlHelper::isFullUrl($dest)) {
180 180
                 try {
181
-                    $dest = UrlHelper::siteUrl($dest, null, null, $redirect['siteId'] ?? null);
181
+                    $dest = UrlHelper::siteUrl($dest, null, null, $redirect[ 'siteId' ] ?? null);
182 182
                 } catch (\yii\base\Exception $e) {
183 183
                 }
184 184
             }
@@ -188,12 +188,12 @@  discard block
 block discarded – undo
188 188
                     $dest .= '?' . $request->getQueryStringWithoutPath();
189 189
                 }
190 190
             }
191
-            $status = $redirect['redirectHttpCode'];
191
+            $status = $redirect[ 'redirectHttpCode' ];
192 192
             Craft::info(
193 193
                 Craft::t(
194 194
                     'retour',
195 195
                     'Redirecting {url} to {dest} with status {status}',
196
-                    ['url' => $url, 'dest' => $dest, 'status' => $status]
196
+                    [ 'url' => $url, 'dest' => $dest, 'status' => $status ]
197 197
                 ),
198 198
                 __METHOD__
199 199
             );
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
     public function getRedirectFromCache($url, int $siteId = 0)
274 274
     {
275 275
         $cache = Craft::$app->getCache();
276
-        $cacheKey = $this::CACHE_KEY.md5($url).$siteId;
276
+        $cacheKey = $this::CACHE_KEY . md5($url) . $siteId;
277 277
         $redirect = $cache->get($cacheKey);
278 278
         Craft::info(
279 279
             Craft::t(
280 280
                 'retour',
281 281
                 'Cached redirect hit for {url}',
282
-                ['url' => $url]
282
+                [ 'url' => $url ]
283 283
             ),
284 284
             __METHOD__
285 285
         );
@@ -301,12 +301,12 @@  discard block
 block discarded – undo
301 301
         } catch (SiteNotFoundException $e) {
302 302
             $siteId = 1;
303 303
         }
304
-        $cacheKey = $this::CACHE_KEY.md5($url).$siteId;
304
+        $cacheKey = $this::CACHE_KEY . md5($url) . $siteId;
305 305
         // Create the dependency tags
306 306
         $dependency = new TagDependency([
307 307
             'tags' => [
308 308
                 $this::GLOBAL_REDIRECTS_CACHE_TAG,
309
-                $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId,
309
+                $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId,
310 310
             ],
311 311
         ]);
312 312
         $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency);
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             Craft::t(
315 315
                 'retour',
316 316
                 'Cached redirect saved for {url}',
317
-                ['url' => $url]
317
+                [ 'url' => $url ]
318 318
             ),
319 319
             __METHOD__
320 320
         );
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
         $result = null;
333 333
         foreach ($redirects as $redirect) {
334 334
             // Figure out what type of source matching to do
335
-            $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly';
336
-            $redirectEnabled = (bool)$redirect['enabled'];
335
+            $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly';
336
+            $redirectEnabled = (bool) $redirect[ 'enabled' ];
337 337
             if ($redirectEnabled === true) {
338 338
                 switch ($redirectSrcMatch) {
339 339
                     case 'pathonly':
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
                         $url = $pathOnly;
347 347
                         break;
348 348
                 }
349
-                $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound';
349
+                $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound';
350 350
                 switch ($redirectMatchType) {
351 351
                     // Do a straight up match
352 352
                     case 'exactmatch':
353
-                        if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) {
353
+                        if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) {
354 354
                             $this->incrementRedirectHitCount($redirect);
355 355
                             $this->saveRedirectToCache($url, $redirect);
356 356
 
@@ -360,14 +360,14 @@  discard block
 block discarded – undo
360 360
 
361 361
                     // Do a regex match
362 362
                     case 'regexmatch':
363
-                        $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i';
363
+                        $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i';
364 364
                         if (preg_match($matchRegEx, $url) === 1) {
365 365
                             $this->incrementRedirectHitCount($redirect);
366 366
                             // If we're not associated with an EntryID, handle capture group replacement
367
-                            if ((int)$redirect['associatedElementId'] === 0) {
368
-                                $redirect['redirectDestUrl'] = preg_replace(
367
+                            if ((int) $redirect[ 'associatedElementId' ] === 0) {
368
+                                $redirect[ 'redirectDestUrl' ] = preg_replace(
369 369
                                     $matchRegEx,
370
-                                    $redirect['redirectDestUrl'],
370
+                                    $redirect[ 'redirectDestUrl' ],
371 371
                                     $url
372 372
                                 );
373 373
                             }
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
                                     'redirect' => &$redirect,
387 387
                                 ],
388 388
                             ];
389
-                            $result = \call_user_func_array([$plugin, 'retourMatch'], $args);
389
+                            $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args);
390 390
                             if ($result) {
391 391
                                 $this->incrementRedirectHitCount($redirect);
392 392
                                 $this->saveRedirectToCache($url, $redirect);
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
             Craft::t(
403 403
                 'retour',
404 404
                 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}',
405
-                ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly]
405
+                [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ]
406 406
             ),
407 407
             __METHOD__
408 408
         );
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
         foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) {
427 427
             /** @var Plugin $plugin */
428 428
             if (method_exists($plugin, 'retourMatch')) {
429
-                $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match');
429
+                $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match');
430 430
             }
431 431
         }
432 432
 
@@ -447,12 +447,12 @@  discard block
 block discarded – undo
447 447
         }
448 448
         // Query the db table
449 449
         $query = (new Query())
450
-            ->from(['{{%retour_static_redirects}}'])
450
+            ->from([ '{{%retour_static_redirects}}' ])
451 451
             ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC');
452 452
         if ($siteId) {
453 453
             $query
454
-                ->where(['siteId' => $siteId])
455
-                ->orWhere(['siteId' => null]);
454
+                ->where([ 'siteId' => $siteId ])
455
+                ->orWhere([ 'siteId' => null ]);
456 456
         }
457 457
         if ($limit) {
458 458
             $query->limit($limit);
@@ -475,8 +475,8 @@  discard block
 block discarded – undo
475 475
     {
476 476
         // Query the db table
477 477
         $redirect = (new Query())
478
-            ->from(['{{%retour_static_redirects}}'])
479
-            ->where(['id' => $id])
478
+            ->from([ '{{%retour_static_redirects}}' ])
479
+            ->where([ 'id' => $id ])
480 480
             ->one();
481 481
 
482 482
         return $redirect;
@@ -494,13 +494,13 @@  discard block
 block discarded – undo
494 494
     {
495 495
         // Query the db table
496 496
         $query = (new Query())
497
-            ->from(['{{%retour_static_redirects}}'])
498
-            ->where(['redirectSrcUrl' => $redirectSrcUrl])
497
+            ->from([ '{{%retour_static_redirects}}' ])
498
+            ->where([ 'redirectSrcUrl' => $redirectSrcUrl ])
499 499
             ;
500 500
         if ($siteId) {
501 501
             $query
502
-                ->andWhere(['siteId' => $siteId])
503
-                ->orWhere(['siteId' => null]);
502
+                ->andWhere([ 'siteId' => $siteId ])
503
+                ->orWhere([ 'siteId' => null ]);
504 504
         }
505 505
         $redirect = $query->one();
506 506
 
@@ -542,13 +542,13 @@  discard block
 block discarded – undo
542 542
     {
543 543
         if ($redirectConfig !== null) {
544 544
             $db = Craft::$app->getDb();
545
-            $redirectConfig['hitCount']++;
546
-            $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime());
545
+            $redirectConfig[ 'hitCount' ]++;
546
+            $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime());
547 547
             Craft::debug(
548 548
                 Craft::t(
549 549
                     'retour',
550 550
                     'Incrementing statistics for: {redirect}',
551
-                    ['redirect' => print_r($redirectConfig, true)]
551
+                    [ 'redirect' => print_r($redirectConfig, true) ]
552 552
                 ),
553 553
                 __METHOD__
554 554
             );
@@ -557,14 +557,14 @@  discard block
 block discarded – undo
557 557
                 $rowsAffected = $db->createCommand()->update(
558 558
                     '{{%retour_static_redirects}}',
559 559
                     [
560
-                        'hitCount' => $redirectConfig['hitCount'],
561
-                        'hitLastTime' => $redirectConfig['hitLastTime'],
560
+                        'hitCount' => $redirectConfig[ 'hitCount' ],
561
+                        'hitLastTime' => $redirectConfig[ 'hitLastTime' ],
562 562
                     ],
563 563
                     [
564
-                        'id' => $redirectConfig['id'],
564
+                        'id' => $redirectConfig[ 'id' ],
565 565
                     ]
566 566
                 )->execute();
567
-                Craft::debug('Rows affected: '.$rowsAffected, __METHOD__);
567
+                Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__);
568 568
             } catch (Exception $e) {
569 569
                 Craft::error($e->getMessage(), __METHOD__);
570 570
             }
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
                 Craft::t(
584 584
                     'retour',
585 585
                     'Error validating redirect {id}: {errors}',
586
-                    ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)]
586
+                    [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ]
587 587
                 ),
588 588
                 __METHOD__
589 589
             );
@@ -593,32 +593,32 @@  discard block
 block discarded – undo
593 593
         // Get the validated model attributes and save them to the db
594 594
         $redirectConfig = $redirect->getAttributes();
595 595
         // 0 for a siteId needs to be converted to null
596
-        if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) {
597
-            $redirectConfig['siteId'] = null;
596
+        if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) {
597
+            $redirectConfig[ 'siteId' ] = null;
598 598
         }
599 599
         // Throw an event to before saving the redirect
600 600
         $db = Craft::$app->getDb();
601 601
         // See if a redirect exists with this source URL already
602
-        if ((int)$redirectConfig['id'] === 0) {
602
+        if ((int) $redirectConfig[ 'id' ] === 0) {
603 603
             // Query the db table
604 604
             $redirect = (new Query())
605
-                ->from(['{{%retour_static_redirects}}'])
606
-                ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']])
607
-                ->andWhere(['siteId' => $redirectConfig['siteId']])
605
+                ->from([ '{{%retour_static_redirects}}' ])
606
+                ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ])
607
+                ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ])
608 608
                 ->one();
609 609
             // If it exists, update it rather than having duplicates
610 610
             if (!empty($redirect)) {
611
-                $redirectConfig['id'] = $redirect['id'];
611
+                $redirectConfig[ 'id' ] = $redirect[ 'id' ];
612 612
             }
613 613
         }
614 614
         // Trigger a 'beforeSaveRedirect' event
615
-        $isNew = (int)$redirectConfig['id'] === 0;
615
+        $isNew = (int) $redirectConfig[ 'id' ] === 0;
616 616
         $event = new RedirectEvent([
617 617
             'isNew' => $isNew,
618
-            'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'],
619
-            'destinationUrl' => $redirectConfig['redirectDestUrl'],
620
-            'matchType' => $redirectConfig['redirectSrcMatch'],
621
-            'redirectType' => $redirectConfig['redirectHttpCode'],
618
+            'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ],
619
+            'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ],
620
+            'matchType' => $redirectConfig[ 'redirectSrcMatch' ],
621
+            'redirectType' => $redirectConfig[ 'redirectHttpCode' ],
622 622
         ]);
623 623
         $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event);
624 624
         if (!$event->isValid) {
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
                 Craft::t(
631 631
                     'retour',
632 632
                     'Updating existing redirect: {redirect}',
633
-                    ['redirect' => print_r($redirectConfig, true)]
633
+                    [ 'redirect' => print_r($redirectConfig, true) ]
634 634
                 ),
635 635
                 __METHOD__
636 636
             );
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
                     '{{%retour_static_redirects}}',
641 641
                     $redirectConfig,
642 642
                     [
643
-                        'id' => $redirectConfig['id'],
643
+                        'id' => $redirectConfig[ 'id' ],
644 644
                     ]
645 645
                 )->execute();
646 646
             } catch (Exception $e) {
@@ -651,11 +651,11 @@  discard block
 block discarded – undo
651 651
                 Craft::t(
652 652
                     'retour',
653 653
                     'Creating new redirect: {redirect}',
654
-                    ['redirect' => print_r($redirectConfig, true)]
654
+                    [ 'redirect' => print_r($redirectConfig, true) ]
655 655
                 ),
656 656
                 __METHOD__
657 657
             );
658
-            unset($redirectConfig['id']);
658
+            unset($redirectConfig[ 'id' ]);
659 659
             // Create a new record
660 660
             try {
661 661
                 $db->createCommand()->insert(
@@ -668,15 +668,15 @@  discard block
 block discarded – undo
668 668
         }
669 669
         // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl
670 670
         $testRedirectConfig = $this->getRedirectByRedirectSrcUrl(
671
-            $redirectConfig['redirectDestUrl'],
672
-            $redirectConfig['siteId']
671
+            $redirectConfig[ 'redirectDestUrl' ],
672
+            $redirectConfig[ 'siteId' ]
673 673
         );
674 674
         if ($testRedirectConfig !== null) {
675 675
             Craft::debug(
676 676
                 Craft::t(
677 677
                     'retour',
678 678
                     'Deleting redirect to prevent a loop: {redirect}',
679
-                    ['redirect' => print_r($testRedirectConfig, true)]
679
+                    [ 'redirect' => print_r($testRedirectConfig, true) ]
680 680
                 ),
681 681
                 __METHOD__
682 682
             );
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
             try {
685 685
                 $db->createCommand()->delete(
686 686
                     '{{%retour_static_redirects}}',
687
-                    ['id' => $testRedirectConfig['id']]
687
+                    [ 'id' => $testRedirectConfig[ 'id' ] ]
688 688
                 )->execute();
689 689
             } catch (Exception $e) {
690 690
                 Craft::error($e->getMessage(), __METHOD__);
@@ -717,10 +717,10 @@  discard block
 block discarded – undo
717 717
      */
718 718
     public function excludeUri($uri): bool
719 719
     {
720
-        $uri = '/'.ltrim($uri, '/');
720
+        $uri = '/' . ltrim($uri, '/');
721 721
         if (!empty(Retour::$settings->excludePatterns)) {
722 722
             foreach (Retour::$settings->excludePatterns as $excludePattern) {
723
-                $pattern = '`'.$excludePattern['pattern'].'`i';
723
+                $pattern = '`' . $excludePattern[ 'pattern' ] . '`i';
724 724
                 if (preg_match($pattern, $uri) === 1) {
725 725
                     return true;
726 726
                 }
Please login to merge, or discard this patch.