Passed
Push — develop ( f47874...08c6ca )
by Andrew
04:18
created
src/models/Redirects.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
     public function rules()
85 85
     {
86 86
         return [
87
-            ['id', 'integer'],
88
-            ['locale', DbStringValidator::class, 'max' => 12],
89
-            ['locale', 'string'],
90
-            ['locale', 'default', 'value' => ''],
91
-            ['associatedElementId', 'default', 'value' => 0],
92
-            ['associatedElementId', 'integer'],
87
+            [ 'id', 'integer' ],
88
+            [ 'locale', DbStringValidator::class, 'max' => 12 ],
89
+            [ 'locale', 'string' ],
90
+            [ 'locale', 'default', 'value' => '' ],
91
+            [ 'associatedElementId', 'default', 'value' => 0 ],
92
+            [ 'associatedElementId', 'integer' ],
93 93
             [
94 94
                 [
95 95
                     'redirectSrcUrl',
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
                 'default',
100 100
                 'value' => ''
101 101
             ],
102
-            ['redirectMatchType', 'default', 'value' => 'exactmatch'],
103
-            ['redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl'],
102
+            [ 'redirectMatchType', 'default', 'value' => 'exactmatch' ],
103
+            [ 'redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl' ],
104 104
             [
105 105
                 [
106 106
                     'redirectSrcUrl',
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
                 ],
129 129
                 'string'
130 130
             ],
131
-            ['redirectHttpCode', 'integer'],
132
-            ['redirectHttpCode', 'default', 'value' => 301],
133
-            ['hitCount', 'default', 'value' => 0],
134
-            ['hitCount', 'integer'],
135
-            ['hitLastTime', 'safe'],
131
+            [ 'redirectHttpCode', 'integer' ],
132
+            [ 'redirectHttpCode', 'default', 'value' => 301 ],
133
+            [ 'hitCount', 'default', 'value' => 0 ],
134
+            [ 'hitCount', 'integer' ],
135
+            [ 'hitLastTime', 'safe' ],
136 136
         ];
137 137
     }
138 138
 }
Please login to merge, or discard this patch.
src/validators/UriValidator.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
             return;
60 60
         }
61 61
         // Make sure there is a leading /
62
-        $value = '/'.ltrim($value, '/');
62
+        $value = '/' . ltrim($value, '/');
63 63
         $model->$attribute = $value;
64 64
     }
65 65
 }
Please login to merge, or discard this patch.
src/controllers/FileController.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     // Protected Properties
62 62
     // =========================================================================
63 63
 
64
-    protected $allowAnonymous = [];
64
+    protected $allowAnonymous = [ ];
65 65
 
66 66
     // Public Methods
67 67
     // =========================================================================
@@ -86,23 +86,23 @@  discard block
 block discarded – undo
86 86
         $headers = array_flip($csv->fetchOne(0));
87 87
         $csv->setOffset(1);
88 88
         $columns = ArrayHelper::filterEmptyStringsFromArray($columns);
89
-        $csv->each(function ($row) use ($headers, $columns) {
89
+        $csv->each(function($row) use ($headers, $columns) {
90 90
             $redirectConfig = [
91 91
                 'id' => 0,
92 92
             ];
93
-            if (isset($columns[0], $headers[$columns[0]])) {
94
-                $redirectConfig['redirectSrcUrl'] = $row[$headers[$columns[0]]] ?? null;
93
+            if (isset($columns[ 0 ], $headers[ $columns[ 0 ] ])) {
94
+                $redirectConfig[ 'redirectSrcUrl' ] = $row[ $headers[ $columns[ 0 ] ] ] ?? null;
95 95
             }
96
-            if (isset($columns[1], $headers[$columns[1]])) {
97
-                $redirectConfig['redirectDestUrl'] = $row[$headers[$columns[1]]] ?? null;
96
+            if (isset($columns[ 1 ], $headers[ $columns[ 1 ] ])) {
97
+                $redirectConfig[ 'redirectDestUrl' ] = $row[ $headers[ $columns[ 1 ] ] ] ?? null;
98 98
             }
99
-            if (isset($columns[2], $headers[$columns[2]])) {
100
-                $redirectConfig['redirectMatchType'] = $row[$headers[$columns[2]]] ?? null;
99
+            if (isset($columns[ 2 ], $headers[ $columns[ 2 ] ])) {
100
+                $redirectConfig[ 'redirectMatchType' ] = $row[ $headers[ $columns[ 2 ] ] ] ?? null;
101 101
             }
102
-            if (isset($columns[3], $headers[$columns[3]])) {
103
-                $redirectConfig['redirectHttpCode'] = $row[$headers[$columns[3]]] ?? null;
102
+            if (isset($columns[ 3 ], $headers[ $columns[ 3 ] ])) {
103
+                $redirectConfig[ 'redirectHttpCode' ] = $row[ $headers[ $columns[ 3 ] ] ] ?? null;
104 104
             }
105
-            Craft::debug('Importing row: '.print_r($redirectConfig, true), __METHOD__);
105
+            Craft::debug('Importing row: ' . print_r($redirectConfig, true), __METHOD__);
106 106
             Retour::$plugin->redirects->saveRedirect($redirectConfig);
107 107
 
108 108
             return true;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function actionImportCsv(string $siteHandle = null): Response
126 126
     {
127
-        $variables = [];
127
+        $variables = [ ];
128 128
         PermissionHelper::controllerPermissionCheck('retour:redirects');
129 129
         // If your CSV document was created or is read on a Macintosh computer,
130 130
         // add the following lines before using the library to help PHP detect line ending in Mac OS X
@@ -142,20 +142,20 @@  discard block
 block discarded – undo
142 142
         } catch (InvalidConfigException $e) {
143 143
             Craft::error($e->getMessage(), __METHOD__);
144 144
         }
145
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
145
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
146 146
             '@nystudio107/retour/assetbundles/retour/dist',
147 147
             true
148 148
         );
149 149
         // Enabled sites
150 150
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
151
-        $variables['controllerHandle'] = 'file';
151
+        $variables[ 'controllerHandle' ] = 'file';
152 152
 
153 153
         // Basic variables
154
-        $variables['fullPageForm'] = true;
155
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
156
-        $variables['pluginName'] = $pluginName;
157
-        $variables['title'] = $templateTitle;
158
-        $variables['crumbs'] = [
154
+        $variables[ 'fullPageForm' ] = true;
155
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
156
+        $variables[ 'pluginName' ] = $pluginName;
157
+        $variables[ 'title' ] = $templateTitle;
158
+        $variables[ 'crumbs' ] = [
159 159
             [
160 160
                 'label' => $pluginName,
161 161
                 'url' => UrlHelper::cpUrl('retour'),
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
                 'url' => UrlHelper::cpUrl('retour/redirects'),
166 166
             ],
167 167
         ];
168
-        $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}";
169
-        $variables['selectedSubnavItem'] = 'redirects';
168
+        $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}";
169
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
170 170
 
171 171
         // The CSV file
172 172
         $file = UploadedFile::getInstanceByName('file');
173 173
         if ($file !== null) {
174
-            $filename = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.uniqid($file->name, true);
174
+            $filename = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . uniqid($file->name, true);
175 175
             $file->saveAs($filename, false);
176 176
             $csv = Reader::createFromPath($file->tempName);
177 177
             $headers = $csv->fetchOne(0);
178 178
             Craft::info(print_r($headers, true), __METHOD__);
179
-            $variables['headers'] = $headers;
180
-            $variables['filename'] = $filename;
179
+            $variables[ 'headers' ] = $headers;
180
+            $variables[ 'filename' ] = $filename;
181 181
         }
182 182
 
183 183
         // Render the template
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
         }
224 224
         // Query the db table
225 225
         $data = (new Query())
226
-            ->from([$table])
226
+            ->from([ $table ])
227 227
             ->select(array_keys($columns))
228 228
             ->orderBy('hitCount DESC')
229 229
             ->all();
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
         $csv = Writer::createFromFileObject(new \SplTempFileObject());
232 232
         $csv->insertOne(array_values($columns));
233 233
         $csv->insertAll($data);
234
-        $csv->output($filename.'.csv');
234
+        $csv->output($filename . '.csv');
235 235
         exit(0);
236 236
     }
237 237
 }
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
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     /**
90 90
      * @var array The URIs for the element before it was saved
91 91
      */
92
-    public $oldElementUris = [];
92
+    public $oldElementUris = [ ];
93 93
 
94 94
     // Public Methods
95 95
     // =========================================================================
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             Craft::t(
115 115
                 'retour',
116 116
                 '{name} plugin loaded',
117
-                ['name' => $this->name]
117
+                [ 'name' => $this->name ]
118 118
             ),
119 119
             __METHOD__
120 120
         );
@@ -134,24 +134,24 @@  discard block
 block discarded – undo
134 134
      */
135 135
     public function getCpNavItem()
136 136
     {
137
-        $subNavs = [];
137
+        $subNavs = [ ];
138 138
         $navItem = parent::getCpNavItem();
139 139
         $currentUser = Craft::$app->getUser()->getIdentity();
140 140
         // Only show sub-navs the user has permission to view
141 141
         if ($currentUser->can('retour:dashboard')) {
142
-            $subNavs['dashboard'] = [
142
+            $subNavs[ 'dashboard' ] = [
143 143
                 'label' => 'Dashboard',
144 144
                 'url' => 'retour/dashboard',
145 145
             ];
146 146
         }
147 147
         if ($currentUser->can('retour:redirects')) {
148
-            $subNavs['redirects'] = [
148
+            $subNavs[ 'redirects' ] = [
149 149
                 'label' => 'Redirects',
150 150
                 'url' => 'retour/redirects',
151 151
             ];
152 152
         }
153 153
         if ($currentUser->can('retour:settings')) {
154
-            $subNavs['settings'] = [
154
+            $subNavs[ 'settings' ] = [
155 155
                 'label' => 'Settings',
156 156
                 'url' => 'retour/settings',
157 157
             ];
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         Event::on(
211 211
             Plugins::class,
212 212
             Plugins::EVENT_AFTER_INSTALL_PLUGIN,
213
-            function (PluginEvent $event) {
213
+            function(PluginEvent $event) {
214 214
                 if ($event->plugin === $this) {
215 215
                     // Invalidate our caches after we've been installed
216 216
                     $this->clearAllCaches();
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         Event::on(
238 238
             CraftVariable::class,
239 239
             CraftVariable::EVENT_INIT,
240
-            function (Event $event) {
240
+            function(Event $event) {
241 241
                 /** @var CraftVariable $variable */
242 242
                 $variable = $event->sender;
243 243
                 $variable->set('retour', RetourVariable::class);
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         Event::on(
248 248
             Elements::class,
249 249
             Elements::EVENT_BEFORE_SAVE_ELEMENT,
250
-            function (ElementEvent $event) {
250
+            function(ElementEvent $event) {
251 251
                 Craft::debug(
252 252
                     'Elements::EVENT_BEFORE_SAVE_ELEMENT',
253 253
                     __METHOD__
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
                         if ($oldElement !== null) {
263 263
                             // Stash the old URLs by element id, and do so only once,
264 264
                             // in case we are called more than once per request
265
-                            if (empty($this->oldElementUris[$oldElement->id])) {
266
-                                $this->oldElementUris[$oldElement->id] = $this->getAllElementUris($oldElement);
265
+                            if (empty($this->oldElementUris[ $oldElement->id ])) {
266
+                                $this->oldElementUris[ $oldElement->id ] = $this->getAllElementUris($oldElement);
267 267
                             }
268 268
                         }
269 269
                     }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
         Event::on(
275 275
             Elements::class,
276 276
             Elements::EVENT_AFTER_SAVE_ELEMENT,
277
-            function (ElementEvent $event) {
277
+            function(ElementEvent $event) {
278 278
                 Craft::debug(
279 279
                     'Elements::EVENT_AFTER_SAVE_ELEMENT',
280 280
                     __METHOD__
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         Event::on(
291 291
             Plugins::class,
292 292
             Plugins::EVENT_AFTER_LOAD_PLUGINS,
293
-            function () {
293
+            function() {
294 294
                 // Install these only after all other plugins have loaded
295 295
                 $request = Craft::$app->getRequest();
296 296
                 // Only respond to non-console site requests
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         Event::on(
315 315
             UrlManager::class,
316 316
             UrlManager::EVENT_REGISTER_SITE_URL_RULES,
317
-            function (RegisterUrlRulesEvent $event) {
317
+            function(RegisterUrlRulesEvent $event) {
318 318
                 Craft::debug(
319 319
                     'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
320 320
                     __METHOD__
@@ -337,15 +337,15 @@  discard block
 block discarded – undo
337 337
         Event::on(
338 338
             Dashboard::class,
339 339
             Dashboard::EVENT_REGISTER_WIDGET_TYPES,
340
-            function (RegisterComponentTypesEvent $event) {
341
-                $event->types[] = RetourWidget::class;
340
+            function(RegisterComponentTypesEvent $event) {
341
+                $event->types[ ] = RetourWidget::class;
342 342
             }
343 343
         );
344 344
         // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES
345 345
         Event::on(
346 346
             UrlManager::class,
347 347
             UrlManager::EVENT_REGISTER_CP_URL_RULES,
348
-            function (RegisterUrlRulesEvent $event) {
348
+            function(RegisterUrlRulesEvent $event) {
349 349
                 Craft::debug(
350 350
                     'UrlManager::EVENT_REGISTER_CP_URL_RULES',
351 351
                     __METHOD__
@@ -361,20 +361,20 @@  discard block
 block discarded – undo
361 361
         Event::on(
362 362
             UserPermissions::class,
363 363
             UserPermissions::EVENT_REGISTER_PERMISSIONS,
364
-            function (RegisterUserPermissionsEvent $event) {
364
+            function(RegisterUserPermissionsEvent $event) {
365 365
                 Craft::debug(
366 366
                     'UserPermissions::EVENT_REGISTER_PERMISSIONS',
367 367
                     __METHOD__
368 368
                 );
369 369
                 // Register our custom permissions
370
-                $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions();
370
+                $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions();
371 371
             }
372 372
         );
373 373
         // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS
374 374
         Event::on(
375 375
             ClearCaches::class,
376 376
             ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
377
-            function (RegisterCacheOptionsEvent $event) {
377
+            function(RegisterCacheOptionsEvent $event) {
378 378
                 Craft::debug(
379 379
                     'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS',
380 380
                     __METHOD__
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
         Event::on(
400 400
             ErrorHandler::class,
401 401
             ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
402
-            function (ExceptionEvent $event) {
402
+            function(ExceptionEvent $event) {
403 403
                 Craft::debug(
404 404
                     'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION',
405 405
                     __METHOD__
@@ -441,16 +441,16 @@  discard block
 block discarded – undo
441 441
     protected function handleElementUriChange(Element $element)
442 442
     {
443 443
         $uris = $this->getAllElementUris($element);
444
-        if (!empty($this->oldElementUris[$element->id])) {
445
-            $oldElementUris = $this->oldElementUris[$element->id];
444
+        if (!empty($this->oldElementUris[ $element->id ])) {
445
+            $oldElementUris = $this->oldElementUris[ $element->id ];
446 446
             foreach ($uris as $siteId => $newUri) {
447
-                if (!empty($oldElementUris[$siteId])) {
448
-                    $oldUri = $oldElementUris[$siteId];
447
+                if (!empty($oldElementUris[ $siteId ])) {
448
+                    $oldUri = $oldElementUris[ $siteId ];
449 449
                     Craft::debug(
450 450
                         Craft::t(
451 451
                             'retour',
452 452
                             'Comparing old: {oldUri} to new: {newUri}',
453
-                            ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)]
453
+                            [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ]
454 454
                         ),
455 455
                         __METHOD__
456 456
                     );
@@ -478,12 +478,12 @@  discard block
 block discarded – undo
478 478
      */
479 479
     protected function getAllElementUris(Element $element): array
480 480
     {
481
-        $uris = [];
481
+        $uris = [ ];
482 482
         $sites = Craft::$app->getSites()->getAllSites();
483 483
         foreach ($sites as $site) {
484 484
             $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id);
485 485
             if ($uri !== null) {
486
-                $uris[$site->id] = $uri;
486
+                $uris[ $site->id ] = $uri;
487 487
             }
488 488
         }
489 489
 
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
             Craft::t(
492 492
                 'retour',
493 493
                 'Getting Element URIs: {uris}',
494
-                ['uris' => print_r($uris, true)]
494
+                [ 'uris' => print_r($uris, true) ]
495 495
             ),
496 496
             __METHOD__
497 497
         );
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
             [
559 559
                 'key' => 'retour-redirect-caches',
560 560
                 'label' => Craft::t('retour', 'Retour redirect caches'),
561
-                'action' => [self::$plugin->redirects, 'invalidateCaches'],
561
+                'action' => [ self::$plugin->redirects, 'invalidateCaches' ],
562 562
             ],
563 563
         ];
564 564
     }
Please login to merge, or discard this patch.
src/services/Statistics.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         }
58 58
         // Query the db table
59 59
         $stats = (new Query())
60
-            ->from(['{{%retour_stats}}'])
60
+            ->from([ '{{%retour_stats}}' ])
61 61
             ->orderBy('hitCount DESC')
62 62
             ->limit(Retour::$settings->statsDisplayLimit)
63 63
             ->all();
@@ -76,10 +76,10 @@  discard block
 block discarded – undo
76 76
     public function getRecentStatistics($days = 1, $handled = false): array
77 77
     {
78 78
         // Ensure is an int
79
-        $handledInt = (int)$handled;
79
+        $handledInt = (int) $handled;
80 80
         // Query the db table
81 81
         $stats = (new Query())
82
-            ->from(['{{%retour_stats}}'])
82
+            ->from([ '{{%retour_stats}}' ])
83 83
             ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )")
84 84
             ->andWhere("handledByRetour = {$handledInt}")
85 85
             ->orderBy('hitLastTime DESC')
@@ -131,21 +131,21 @@  discard block
 block discarded – undo
131 131
         $stats->validate();
132 132
         // Find any existing retour_stats record
133 133
         $statsConfig = (new Query())
134
-            ->from(['{{%retour_stats}}'])
135
-            ->where(['redirectSrcUrl' => $stats->redirectSrcUrl])
134
+            ->from([ '{{%retour_stats}}' ])
135
+            ->where([ 'redirectSrcUrl' => $stats->redirectSrcUrl ])
136 136
             ->one();
137 137
         // If no record is found, initialize some values
138 138
         if ($statsConfig === null) {
139 139
             $stats->id = 0;
140 140
             $stats->hitCount = 0;
141 141
         } else {
142
-            $stats->id = $statsConfig['id'];
143
-            $stats->hitCount = $statsConfig['hitCount'];
142
+            $stats->id = $statsConfig[ 'id' ];
143
+            $stats->hitCount = $statsConfig[ 'hitCount' ];
144 144
         }
145 145
         // Merge in the updated info
146 146
         $stats->referrerUrl = $referrer;
147 147
         $stats->hitLastTime = Db::prepareDateForDb(new \DateTime());
148
-        $stats->handledByRetour = (int)$handled;
148
+        $stats->handledByRetour = (int) $handled;
149 149
         $stats->hitCount++;
150 150
         $statsConfig = $stats->getAttributes();
151 151
         // Record the updated statistics
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
                 Craft::t(
193 193
                     'retour',
194 194
                     'Trimmed {rows} from retour_stats table',
195
-                    ['rows' => $affectedRows]
195
+                    [ 'rows' => $affectedRows ]
196 196
                 ),
197 197
                 __METHOD__
198 198
             );
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
                 Craft::t(
212 212
                     'retour',
213 213
                     'Error validating statistics {id}: {errors}',
214
-                    ['id' => $stats->id, 'errors' => print_r($stats->getErrors(), true)]
214
+                    [ 'id' => $stats->id, 'errors' => print_r($stats->getErrors(), true) ]
215 215
                 ),
216 216
                 __METHOD__
217 217
             );
@@ -221,21 +221,21 @@  discard block
 block discarded – undo
221 221
         // Get the validated model attributes and save them to the db
222 222
         $statsConfig = $stats->getAttributes();
223 223
         $db = Craft::$app->getDb();
224
-        if ($statsConfig['id'] !== 0) {
224
+        if ($statsConfig[ 'id' ] !== 0) {
225 225
             // Update the existing record
226 226
             try {
227 227
                 $result = $db->createCommand()->update(
228 228
                     '{{%retour_stats}}',
229 229
                     $statsConfig,
230 230
                     [
231
-                        'id' => $statsConfig['id'],
231
+                        'id' => $statsConfig[ 'id' ],
232 232
                     ]
233 233
                 )->execute();
234 234
             } catch (Exception $e) {
235 235
                 Craft::error($e->getMessage(), __METHOD__);
236 236
             }
237 237
         } else {
238
-            unset($statsConfig['id']);
238
+            unset($statsConfig[ 'id' ]);
239 239
             // Create a new record
240 240
             try {
241 241
                 $db->createCommand()->insert(
Please login to merge, or discard this patch.
src/services/Redirects.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
                 Craft::t(
86 86
                     'retour',
87 87
                     '404 URL: {url}',
88
-                    ['url' => $url]
88
+                    [ 'url' => $url ]
89 89
                 ),
90 90
                 __METHOD__
91 91
             );
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
     {
115 115
         $response = Craft::$app->getResponse();
116 116
         if ($redirect !== null) {
117
-            $dest = $redirect['redirectDestUrl'];
118
-            $status = $redirect['redirectHttpCode'];
117
+            $dest = $redirect[ 'redirectDestUrl' ];
118
+            $status = $redirect[ 'redirectHttpCode' ];
119 119
             Craft::info(
120 120
                 Craft::t(
121 121
                     'retour',
122 122
                     'Redirecting {url} to {dest} with status {status}',
123
-                    ['url' => $url, 'dest' => $dest, 'status' => $status]
123
+                    [ 'url' => $url, 'dest' => $dest, 'status' => $status ]
124 124
                 ),
125 125
                 __METHOD__
126 126
             );
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
     public function getRedirectFromCache($url)
173 173
     {
174 174
         $cache = Craft::$app->getCache();
175
-        $cacheKey = $this::CACHE_KEY.md5($url);
175
+        $cacheKey = $this::CACHE_KEY . md5($url);
176 176
         $redirect = $cache->get($cacheKey);
177 177
         Craft::info(
178 178
             Craft::t(
179 179
                 'retour',
180 180
                 'Cached redirect hit for {url}',
181
-                ['url' => $url]
181
+                [ 'url' => $url ]
182 182
             ),
183 183
             __METHOD__
184 184
         );
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public function saveRedirectToCache($url, $redirect)
194 194
     {
195
-        $cacheKey = $this::CACHE_KEY.md5($url);
195
+        $cacheKey = $this::CACHE_KEY . md5($url);
196 196
         $cache = Craft::$app->getCache();
197 197
         // Get the current site id
198 198
         $sites = Craft::$app->getSites();
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $dependency = new TagDependency([
206 206
             'tags' => [
207 207
                 $this::GLOBAL_REDIRECTS_CACHE_TAG,
208
-                $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId,
208
+                $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId,
209 209
             ],
210 210
         ]);
211 211
         $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency);
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             Craft::t(
214 214
                 'retour',
215 215
                 'Cached redirect saved for {url}',
216
-                ['url' => $url]
216
+                [ 'url' => $url ]
217 217
             ),
218 218
             __METHOD__
219 219
         );
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
     {
230 230
         $result = null;
231 231
         foreach ($redirects as $redirect) {
232
-            $redirectMatchType = $redirect['redirectMatchType'] ?? null;
232
+            $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? null;
233 233
             switch ($redirectMatchType) {
234 234
                 // Do a straight up match
235 235
                 case 'exactmatch':
236
-                    if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) {
236
+                    if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) {
237 237
                         $this->incrementRedirectHitCount($redirect);
238 238
                         $this->saveRedirectToCache($url, $redirect);
239 239
 
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 
244 244
                 // Do a regex match
245 245
                 case 'regexmatch':
246
-                    $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i';
246
+                    $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i';
247 247
                     if (preg_match($matchRegEx, $url) === 1) {
248 248
                         $this->incrementRedirectHitCount($redirect);
249 249
                         // If we're not associated with an EntryID, handle capture group replacement
250
-                        if ((int)$redirect['associatedElementId'] === 0) {
251
-                            $redirect['redirectDestUrl'] = preg_replace(
250
+                        if ((int) $redirect[ 'associatedElementId' ] === 0) {
251
+                            $redirect[ 'redirectDestUrl' ] = preg_replace(
252 252
                                 $matchRegEx,
253
-                                $redirect['redirectDestUrl'],
253
+                                $redirect[ 'redirectDestUrl' ],
254 254
                                 $url
255 255
                             );
256 256
                         }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
                                 'redirect' => &$redirect,
270 270
                             ],
271 271
                         ];
272
-                        $result = \call_user_func_array([$plugin, 'retourMatch'], $args);
272
+                        $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args);
273 273
                         if ($result) {
274 274
                             $this->incrementRedirectHitCount($redirect);
275 275
                             $this->saveRedirectToCache($url, $redirect);
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
             Craft::t(
285 285
                 'retour',
286 286
                 'Not handled: {url}',
287
-                ['url' => $url]
287
+                [ 'url' => $url ]
288 288
             ),
289 289
             __METHOD__
290 290
         );
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
         foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) {
309 309
             /** @var Plugin $plugin */
310 310
             if (method_exists($plugin, 'retourMatch')) {
311
-                $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match');
311
+                $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match');
312 312
             }
313 313
         }
314 314
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
         }
329 329
         // Query the db table
330 330
         $query = (new Query())
331
-            ->from(['{{%retour_static_redirects}}'])
331
+            ->from([ '{{%retour_static_redirects}}' ])
332 332
             ->orderBy('redirectMatchType ASC, hitCount DESC');
333 333
         if ($limit) {
334 334
             $query->limit($limit);
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
     {
352 352
         // Query the db table
353 353
         $redirect = (new Query())
354
-            ->from(['{{%retour_static_redirects}}'])
355
-            ->where(['id' => $id])
354
+            ->from([ '{{%retour_static_redirects}}' ])
355
+            ->where([ 'id' => $id ])
356 356
             ->one();
357 357
 
358 358
         return $redirect;
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
     {
370 370
         // Query the db table
371 371
         $redirect = (new Query())
372
-            ->from(['{{%retour_static_redirects}}'])
373
-            ->where(['redirectSrcUrl' => $redirectSrcUrl])
372
+            ->from([ '{{%retour_static_redirects}}' ])
373
+            ->where([ 'redirectSrcUrl' => $redirectSrcUrl ])
374 374
             ->one();
375 375
 
376 376
         return $redirect;
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
     {
412 412
         if ($redirectConfig !== null) {
413 413
             $db = Craft::$app->getDb();
414
-            $redirectConfig['hitCount']++;
415
-            $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime());
414
+            $redirectConfig[ 'hitCount' ]++;
415
+            $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime());
416 416
             Craft::debug(
417 417
                 Craft::t(
418 418
                     'retour',
419 419
                     'Incrementing statistics for: {redirect}',
420
-                    ['redirect' => print_r($redirectConfig, true)]
420
+                    [ 'redirect' => print_r($redirectConfig, true) ]
421 421
                 ),
422 422
                 __METHOD__
423 423
             );
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
                 $rowsAffected = $db->createCommand()->update(
427 427
                     '{{%retour_static_redirects}}',
428 428
                     [
429
-                        'hitCount' => $redirectConfig['hitCount'],
430
-                        'hitLastTime' => $redirectConfig['hitLastTime'],
429
+                        'hitCount' => $redirectConfig[ 'hitCount' ],
430
+                        'hitLastTime' => $redirectConfig[ 'hitLastTime' ],
431 431
                     ],
432 432
                     [
433
-                        'id' => $redirectConfig['id'],
433
+                        'id' => $redirectConfig[ 'id' ],
434 434
                     ]
435 435
                 )->execute();
436
-                Craft::debug('Rows affected: '.$rowsAffected, __METHOD__);
436
+                Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__);
437 437
             } catch (Exception $e) {
438 438
                 Craft::error($e->getMessage(), __METHOD__);
439 439
             }
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
                 Craft::t(
453 453
                     'retour',
454 454
                     'Error validating redirect {id}: {errors}',
455
-                    ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)]
455
+                    [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ]
456 456
                 ),
457 457
                 __METHOD__
458 458
             );
@@ -463,23 +463,23 @@  discard block
 block discarded – undo
463 463
         $redirectConfig = $redirect->getAttributes();
464 464
         $db = Craft::$app->getDb();
465 465
         // See if a redirect exists with this source URL already
466
-        if ((int)$redirectConfig['id'] === 0) {
466
+        if ((int) $redirectConfig[ 'id' ] === 0) {
467 467
             // Query the db table
468 468
             $redirect = (new Query())
469
-                ->from(['{{%retour_static_redirects}}'])
470
-                ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']])
469
+                ->from([ '{{%retour_static_redirects}}' ])
470
+                ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ])
471 471
                 ->one();
472 472
             // If it exists, update it rather than having duplicates
473 473
             if (!empty($redirect)) {
474
-                $redirectConfig['id'] = $redirect['id'];
474
+                $redirectConfig[ 'id' ] = $redirect[ 'id' ];
475 475
             }
476 476
         }
477
-        if ((int)$redirectConfig['id'] !== 0) {
477
+        if ((int) $redirectConfig[ 'id' ] !== 0) {
478 478
             Craft::debug(
479 479
                 Craft::t(
480 480
                     'retour',
481 481
                     'Updating existing redirect: {redirect}',
482
-                    ['redirect' => print_r($redirectConfig, true)]
482
+                    [ 'redirect' => print_r($redirectConfig, true) ]
483 483
                 ),
484 484
                 __METHOD__
485 485
             );
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
                     '{{%retour_static_redirects}}',
490 490
                     $redirectConfig,
491 491
                     [
492
-                        'id' => $redirectConfig['id'],
492
+                        'id' => $redirectConfig[ 'id' ],
493 493
                     ]
494 494
                 )->execute();
495 495
             } catch (Exception $e) {
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
                 Craft::t(
501 501
                     'retour',
502 502
                     'Creating new redirect: {redirect}',
503
-                    ['redirect' => print_r($redirectConfig, true)]
503
+                    [ 'redirect' => print_r($redirectConfig, true) ]
504 504
                 ),
505 505
                 __METHOD__
506 506
             );
507
-            unset($redirectConfig['id']);
507
+            unset($redirectConfig[ 'id' ]);
508 508
             // Create a new record
509 509
             try {
510 510
                 $db->createCommand()->insert(
@@ -516,13 +516,13 @@  discard block
 block discarded – undo
516 516
             }
517 517
         }
518 518
         // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl
519
-        $testRedirectConfig = $this->getRedirectByRedirectSrcUrl($redirectConfig['redirectDestUrl']);
519
+        $testRedirectConfig = $this->getRedirectByRedirectSrcUrl($redirectConfig[ 'redirectDestUrl' ]);
520 520
         if ($testRedirectConfig !== null) {
521 521
             Craft::debug(
522 522
                 Craft::t(
523 523
                     'retour',
524 524
                     'Deleting redirect to prevent a loop: {redirect}',
525
-                    ['redirect' => print_r($testRedirectConfig, true)]
525
+                    [ 'redirect' => print_r($testRedirectConfig, true) ]
526 526
                 ),
527 527
                 __METHOD__
528 528
             );
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
             try {
531 531
                 $db->createCommand()->delete(
532 532
                     '{{%retour_static_redirects}}',
533
-                    ['id' => $testRedirectConfig['id']]
533
+                    [ 'id' => $testRedirectConfig[ 'id' ] ]
534 534
                 )->execute();
535 535
             } catch (Exception $e) {
536 536
                 Craft::error($e->getMessage(), __METHOD__);
Please login to merge, or discard this patch.
src/controllers/TablesController.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $filter = ''
61 61
     ): Response {
62 62
         PermissionHelper::controllerPermissionCheck('retour:dashboard');
63
-        $data = [];
63
+        $data = [ ];
64 64
         $sortField = 'hitCount';
65 65
         $sortType = 'DESC';
66 66
         // Figure out the sorting type
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         // Query the db table
75 75
         $offset = ($page - 1) * $per_page;
76 76
         $query = (new Query())
77
-            ->from(['{{%retour_stats}}'])
77
+            ->from([ '{{%retour_stats}}' ])
78 78
             ->offset($offset)
79 79
             ->limit($per_page)
80 80
             ->orderBy("{$sortField} {$sortType}");
@@ -85,25 +85,25 @@  discard block
 block discarded – undo
85 85
         $stats = $query->all();
86 86
         // Add in the `addLink` field
87 87
         foreach ($stats as &$stat) {
88
-            $stat['addLink'] = '';
89
-            if (!$stat['handledByRetour']) {
90
-                $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/'));
91
-                $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [
88
+            $stat[ 'addLink' ] = '';
89
+            if (!$stat[ 'handledByRetour' ]) {
90
+                $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/'));
91
+                $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [
92 92
                     'defaultUrl' => $encodedUrl
93 93
                 ]);
94 94
             }
95 95
         }
96 96
         // Format the data for the API
97 97
         if ($stats) {
98
-            $data['data'] = $stats;
98
+            $data[ 'data' ] = $stats;
99 99
             $query = (new Query())
100
-                ->from(['{{%retour_stats}}']);
100
+                ->from([ '{{%retour_stats}}' ]);
101 101
             if ($filter !== '') {
102 102
                 $query->where("`redirectSrcUrl` LIKE '%{$filter}%'");
103 103
                 $query->orWhere("`referrerUrl` LIKE '%{$filter}%'");
104 104
             }
105 105
             $count = $query->count();
106
-            $data['links']['pagination'] = [
106
+            $data[ 'links' ][ 'pagination' ] = [
107 107
                 'total' => $count,
108 108
                 'per_page' => $per_page,
109 109
                 'current_page' => $page,
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         $filter = ''
137 137
     ): Response {
138 138
         PermissionHelper::controllerPermissionCheck('retour:redirects');
139
-        $data = [];
139
+        $data = [ ];
140 140
         $sortField = 'hitCount';
141 141
         $sortType = 'DESC';
142 142
         // Figure out the sorting type
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
         // Query the db table
151 151
         $offset = ($page - 1) * $per_page;
152 152
         $query = (new Query())
153
-            ->from(['{{%retour_static_redirects}}'])
153
+            ->from([ '{{%retour_static_redirects}}' ])
154 154
             ->offset($offset)
155 155
             ->limit($per_page)
156 156
             ->orderBy("{$sortField} {$sortType}");
@@ -161,20 +161,20 @@  discard block
 block discarded – undo
161 161
         $redirects = $query->all();
162 162
         // Add in the `deleteLink` field
163 163
         foreach ($redirects as &$redirect) {
164
-            $redirect['deleteLink'] = UrlHelper::cpUrl('retour/delete-redirect/'.$redirect['id']);
165
-            $redirect['redirectSrcUrl'].= '|||'.UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']);
164
+            $redirect[ 'deleteLink' ] = UrlHelper::cpUrl('retour/delete-redirect/' . $redirect[ 'id' ]);
165
+            $redirect[ 'redirectSrcUrl' ] .= '|||' . UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]);
166 166
         }
167 167
         // Format the data for the API
168 168
         if ($redirects) {
169
-            $data['data'] = $redirects;
169
+            $data[ 'data' ] = $redirects;
170 170
             $query = (new Query())
171
-                ->from(['{{%retour_static_redirects}}']);
171
+                ->from([ '{{%retour_static_redirects}}' ]);
172 172
             if ($filter !== '') {
173 173
                 $query->where("`redirectSrcUrl` LIKE '%{$filter}%'");
174 174
                 $query->orWhere("`redirectDestUrl` LIKE '%{$filter}%'");
175 175
             }
176 176
             $count = $query->count();
177
-            $data['links']['pagination'] = [
177
+            $data[ 'links' ][ 'pagination' ] = [
178 178
                 'total' => $count,
179 179
                 'per_page' => $per_page,
180 180
                 'current_page' => $page,
Please login to merge, or discard this patch.
src/console/controllers/StatsController.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -66,13 +66,13 @@
 block discarded – undo
66 66
      */
67 67
     public function actionTrim(): int
68 68
     {
69
-        echo Craft::t('retour', 'Trimming statistics').PHP_EOL;
69
+        echo Craft::t('retour', 'Trimming statistics') . PHP_EOL;
70 70
         $affectedRows = Retour::$plugin->statistics->trimStatistics($this->limit);
71 71
         echo Craft::t(
72 72
             'retour',
73 73
             'Trimmed {rows} from retour_stats table',
74
-            ['rows' => $affectedRows]
75
-        ).PHP_EOL;
74
+            [ 'rows' => $affectedRows ]
75
+        ) . PHP_EOL;
76 76
 
77 77
         return 0;
78 78
     }
Please login to merge, or discard this patch.
src/controllers/StatisticsController.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     // Protected Properties
41 41
     // =========================================================================
42 42
 
43
-    protected $allowAnonymous = [];
43
+    protected $allowAnonymous = [ ];
44 44
 
45 45
     // Public Methods
46 46
     // =========================================================================
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function actionDashboard(string $siteHandle = null, bool $showWelcome = false): Response
58 58
     {
59
-        $variables = [];
59
+        $variables = [ ];
60 60
         PermissionHelper::controllerPermissionCheck('retour:dashboard');
61 61
         // Trim the statistics
62 62
         Retour::$plugin->statistics->trimStatistics();
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
         } catch (InvalidConfigException $e) {
72 72
             Craft::error($e->getMessage(), __METHOD__);
73 73
         }
74
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
74
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
75 75
             '@nystudio107/retour/assetbundles/retour/dist',
76 76
             true
77 77
         );
78 78
         // Enabled sites
79 79
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
80
-        $variables['controllerHandle'] = 'statistics';
80
+        $variables[ 'controllerHandle' ] = 'statistics';
81 81
 
82 82
         // Basic variables
83
-        $variables['fullPageForm'] = false;
84
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
85
-        $variables['pluginName'] = $pluginName;
86
-        $variables['title'] = $templateTitle;
87
-        $variables['crumbs'] = [
83
+        $variables[ 'fullPageForm' ] = false;
84
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
85
+        $variables[ 'pluginName' ] = $pluginName;
86
+        $variables[ 'title' ] = $templateTitle;
87
+        $variables[ 'crumbs' ] = [
88 88
             [
89 89
                 'label' => $pluginName,
90 90
                 'url' => UrlHelper::cpUrl('retour'),
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
                 'url' => UrlHelper::cpUrl('retour/dashboard'),
95 95
             ],
96 96
         ];
97
-        $variables['docTitle'] = "{$pluginName} - {$templateTitle}";
98
-        $variables['selectedSubnavItem'] = 'dashboard';
99
-        $variables['showWelcome'] = $showWelcome;
97
+        $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}";
98
+        $variables[ 'selectedSubnavItem' ] = 'dashboard';
99
+        $variables[ 'showWelcome' ] = $showWelcome;
100 100
 
101 101
         // Render the template
102 102
         return $this->renderTemplate('retour/dashboard/index', $variables);
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             Craft::t(
115 115
                 'retour',
116 116
                 'Retour statistics cleared: {error}',
117
-                ['error' => $error]
117
+                [ 'error' => $error ]
118 118
             ),
119 119
             __METHOD__
120 120
         );
Please login to merge, or discard this patch.