Passed
Push — develop ( 4c2b06...c4b8a5 )
by Andrew
08:04
created
src/controllers/FileController.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     // Protected Properties
80 80
     // =========================================================================
81 81
 
82
-    protected $allowAnonymous = [];
82
+    protected $allowAnonymous = [ ];
83 83
 
84 84
     // Public Methods
85 85
     // =========================================================================
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      */
155 155
     public function actionImportCsv(string $siteHandle = null): Response
156 156
     {
157
-        $variables = [];
157
+        $variables = [ ];
158 158
         PermissionHelper::controllerPermissionCheck('retour:redirects');
159 159
         // If your CSV document was created or is read on a Macintosh computer,
160 160
         // add the following lines before using the library to help PHP detect line ending in Mac OS X
@@ -172,38 +172,38 @@  discard block
 block discarded – undo
172 172
         } catch (InvalidConfigException $e) {
173 173
             Craft::error($e->getMessage(), __METHOD__);
174 174
         }
175
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
175
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
176 176
             '@nystudio107/retour/assetbundles/retour/dist',
177 177
             true
178 178
         );
179 179
         // Enabled sites
180 180
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
181
-        $variables['controllerHandle'] = 'file';
181
+        $variables[ 'controllerHandle' ] = 'file';
182 182
 
183 183
         // Basic variables
184
-        $variables['fullPageForm'] = true;
185
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
186
-        $variables['pluginName'] = $pluginName;
187
-        $variables['title'] = $templateTitle;
188
-        $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : '';
189
-        $variables['crumbs'] = [
184
+        $variables[ 'fullPageForm' ] = true;
185
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
186
+        $variables[ 'pluginName' ] = $pluginName;
187
+        $variables[ 'title' ] = $templateTitle;
188
+        $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : '';
189
+        $variables[ 'crumbs' ] = [
190 190
             [
191 191
                 'label' => $pluginName,
192 192
                 'url' => UrlHelper::cpUrl('retour'),
193 193
             ],
194 194
             [
195 195
                 'label' => 'Redirects',
196
-                'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri),
196
+                'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri),
197 197
             ],
198 198
         ];
199
-        $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}";
200
-        $variables['selectedSubnavItem'] = 'redirects';
199
+        $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}";
200
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
201 201
 
202 202
         // The CSV file
203 203
         $file = UploadedFile::getInstanceByName('file');
204 204
         if ($file !== null) {
205 205
             $filename = uniqid($file->name, true);
206
-            $filePath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$filename;
206
+            $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
207 207
             $file->saveAs($filePath, false);
208 208
             // Also save the file to the cache as a backup way to access it
209 209
             $cache = Craft::$app->getCache();
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
             $csv = Reader::createFromPath($file->tempName);
220 220
             $headers = $csv->fetchOne(0);
221 221
             Craft::info(print_r($headers, true), __METHOD__);
222
-            $variables['headers'] = $headers;
223
-            $variables['filename'] = $filePath;
222
+            $variables[ 'headers' ] = $headers;
223
+            $variables[ 'filename' ] = $filePath;
224 224
         }
225 225
 
226 226
         // Render the template
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         }
267 267
         // Query the db table
268 268
         $data = (new Query())
269
-            ->from([$table])
269
+            ->from([ $table ])
270 270
             ->select(array_keys($columns))
271 271
             ->orderBy('hitCount DESC')
272 272
             ->all();
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         }
280 280
         $csv->insertOne(array_values($columns));
281 281
         $csv->insertAll($data);
282
-        $csv->output($filename.'.csv');
282
+        $csv->output($filename . '.csv');
283 283
         exit(0);
284 284
     }
285 285
 
@@ -292,16 +292,16 @@  discard block
 block discarded – undo
292 292
     {
293 293
         $csv->setOffset(1);
294 294
         $columns = ArrayHelper::filterEmptyStringsFromArray($columns);
295
-        $csv->each(function ($row) use ($headers, $columns) {
295
+        $csv->each(function($row) use ($headers, $columns) {
296 296
             $redirectConfig = [
297 297
                 'id' => 0,
298 298
             ];
299 299
             $index = 0;
300 300
             foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) {
301
-                if (isset($columns[$index], $headers[$columns[$index]])) {
302
-                    $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]])
301
+                if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) {
302
+                    $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ])
303 303
                         ? null
304
-                        : $row[$headers[$columns[$index]]];
304
+                        : $row[ $headers[ $columns[ $index ] ] ];
305 305
                 }
306 306
                 $index++;
307 307
             }
@@ -331,10 +331,10 @@  discard block
 block discarded – undo
331 331
             ];
332 332
             $index = 0;
333 333
             foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) {
334
-                if (isset($columns[$index], $headers[$columns[$index]])) {
335
-                    $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]])
334
+                if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) {
335
+                    $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ])
336 336
                         ? null
337
-                        : $row[$headers[$columns[$index]]];
337
+                        : $row[ $headers[ $columns[ $index ] ] ];
338 338
                 }
339 339
                 $index++;
340 340
             }
Please login to merge, or discard this patch.
src/Retour.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
     /**
126 126
      * @inheritdoc
127 127
      */
128
-    public function __construct($id, $parent = null, array $config = [])
128
+    public function __construct($id, $parent = null, array $config = [ ])
129 129
     {
130
-        $config['components'] = [
130
+        $config[ 'components' ] = [
131 131
             'redirects' => Redirects::class,
132 132
             'statistics' => Statistics::class,
133 133
             // Register the manifest service
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
     /**
164 164
      * @var array The URIs for the element before it was saved
165 165
      */
166
-    public $oldElementUris = [];
166
+    public $oldElementUris = [ ];
167 167
 
168 168
     // Public Methods
169 169
     // =========================================================================
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
             Craft::t(
198 198
                 'retour',
199 199
                 '{name} plugin loaded',
200
-                ['name' => $this->name]
200
+                [ 'name' => $this->name ]
201 201
             ),
202 202
             __METHOD__
203 203
         );
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public function getCpNavItem()
219 219
     {
220
-        $subNavs = [];
220
+        $subNavs = [ ];
221 221
         $navItem = parent::getCpNavItem();
222 222
         $currentUser = Craft::$app->getUser()->getIdentity();
223 223
         // Only show sub-navs the user has permission to view
224 224
         if ($currentUser->can('retour:dashboard')) {
225
-            $subNavs['dashboard'] = [
225
+            $subNavs[ 'dashboard' ] = [
226 226
                 'label' => 'Dashboard',
227 227
                 'url' => 'retour/dashboard',
228 228
             ];
229 229
         }
230 230
         if ($currentUser->can('retour:redirects')) {
231
-            $subNavs['redirects'] = [
231
+            $subNavs[ 'redirects' ] = [
232 232
                 'label' => 'Redirects',
233 233
                 'url' => 'retour/redirects',
234 234
             ];
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
             $editableSettings = false;
240 240
         }
241 241
         if ($currentUser->can('retour:settings') && $editableSettings) {
242
-            $subNavs['settings'] = [
242
+            $subNavs[ 'settings' ] = [
243 243
                 'label' => 'Settings',
244 244
                 'url' => 'retour/settings',
245 245
             ];
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         }
251 251
         // A single sub nav item is redundant
252 252
         if (count($subNavs) === 1) {
253
-            $subNavs = [];
253
+            $subNavs = [ ];
254 254
         }
255 255
         $navItem = array_merge($navItem, [
256 256
             'subnav' => $subNavs,
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
         Event::on(
307 307
             ClearCaches::class,
308 308
             ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
309
-            function (RegisterCacheOptionsEvent $event) {
309
+            function(RegisterCacheOptionsEvent $event) {
310 310
                 Craft::debug(
311 311
                     'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS',
312 312
                     __METHOD__
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         Event::on(
323 323
             Plugins::class,
324 324
             Plugins::EVENT_AFTER_INSTALL_PLUGIN,
325
-            function (PluginEvent $event) {
325
+            function(PluginEvent $event) {
326 326
                 if ($event->plugin === $this) {
327 327
                     // Invalidate our caches after we've been installed
328 328
                     $this->clearAllCaches();
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
         Event::on(
350 350
             CraftVariable::class,
351 351
             CraftVariable::EVENT_INIT,
352
-            function (Event $event) {
352
+            function(Event $event) {
353 353
                 /** @var CraftVariable $variable */
354 354
                 $variable = $event->sender;
355 355
                 $variable->set('retour', [
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
         Event::on(
363 363
             Elements::class,
364 364
             Elements::EVENT_BEFORE_SAVE_ELEMENT,
365
-            function (ElementEvent $event) {
365
+            function(ElementEvent $event) {
366 366
                 Craft::debug(
367 367
                     'Elements::EVENT_BEFORE_SAVE_ELEMENT',
368 368
                     __METHOD__
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
                         if (strpos($element->uri, '__temp_') === false && !$element->propagating) {
386 386
                             // Stash the old URLs by element id, and do so only once,
387 387
                             // in case we are called more than once per request
388
-                            if (empty($this->oldElementUris[$element->id])) {
389
-                                $this->oldElementUris[$element->id] = $this->getAllElementUris($element);
388
+                            if (empty($this->oldElementUris[ $element->id ])) {
389
+                                $this->oldElementUris[ $element->id ] = $this->getAllElementUris($element);
390 390
                             }
391 391
                         }
392 392
                     }
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
         Event::on(
398 398
             Elements::class,
399 399
             Elements::EVENT_AFTER_SAVE_ELEMENT,
400
-            function (ElementEvent $event) {
400
+            function(ElementEvent $event) {
401 401
                 Craft::debug(
402 402
                     'Elements::EVENT_AFTER_SAVE_ELEMENT',
403 403
                     __METHOD__
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
         Event::on(
420 420
             Plugins::class,
421 421
             Plugins::EVENT_AFTER_LOAD_PLUGINS,
422
-            function () {
422
+            function() {
423 423
                 // Install these only after all other plugins have loaded
424 424
                 $request = Craft::$app->getRequest();
425 425
                 // Only respond to non-console site requests
@@ -437,26 +437,26 @@  discard block
 block discarded – undo
437 437
             Event::on(
438 438
                 Gql::class,
439 439
                 Gql::EVENT_REGISTER_GQL_TYPES,
440
-                function (RegisterGqlTypesEvent $event) {
440
+                function(RegisterGqlTypesEvent $event) {
441 441
                     Craft::debug(
442 442
                         'Gql::EVENT_REGISTER_GQL_TYPES',
443 443
                         __METHOD__
444 444
                     );
445
-                    $event->types[] = RetourInterface::class;
445
+                    $event->types[ ] = RetourInterface::class;
446 446
                 }
447 447
             );
448 448
             // Handler: Gql::EVENT_REGISTER_GQL_QUERIES
449 449
             Event::on(
450 450
                 Gql::class,
451 451
                 Gql::EVENT_REGISTER_GQL_QUERIES,
452
-                function (RegisterGqlQueriesEvent $event) {
452
+                function(RegisterGqlQueriesEvent $event) {
453 453
                     Craft::debug(
454 454
                         'Gql::EVENT_REGISTER_GQL_QUERIES',
455 455
                         __METHOD__
456 456
                     );
457 457
                     $queries = RetourQuery::getQueries();
458 458
                     foreach ($queries as $key => $value) {
459
-                        $event->queries[$key] = $value;
459
+                        $event->queries[ $key ] = $value;
460 460
                     }
461 461
                 }
462 462
             );
@@ -465,13 +465,13 @@  discard block
 block discarded – undo
465 465
                 Event::on(
466 466
                     Gql::class,
467 467
                     Gql::EVENT_REGISTER_GQL_SCHEMA_COMPONENTS,
468
-                    function (RegisterGqlSchemaComponentsEvent $event) {
468
+                    function(RegisterGqlSchemaComponentsEvent $event) {
469 469
                         Craft::debug(
470 470
                             'Gql::EVENT_REGISTER_GQL_SCHEMA_COMPONENTS',
471 471
                             __METHOD__
472 472
                         );
473 473
                         $label = Craft::t('retour', 'Retour');
474
-                        $event->queries[$label]['retour.all:read'] = ['label' => Craft::t('retour', 'Query Retour data')];
474
+                        $event->queries[ $label ][ 'retour.all:read' ] = [ 'label' => Craft::t('retour', 'Query Retour data') ];
475 475
                     }
476 476
                 );
477 477
             }
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
             Event::on(
482 482
                 Schema::class,
483 483
                 AlterSchemaFields::EVENT,
484
-                [GetCraftQLSchema::class, 'handle']
484
+                [ GetCraftQLSchema::class, 'handle' ]
485 485
             );
486 486
         }
487 487
     }
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
         Event::on(
496 496
             UrlManager::class,
497 497
             UrlManager::EVENT_REGISTER_SITE_URL_RULES,
498
-            function (RegisterUrlRulesEvent $event) {
498
+            function(RegisterUrlRulesEvent $event) {
499 499
                 Craft::debug(
500 500
                     'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
501 501
                     __METHOD__
@@ -518,15 +518,15 @@  discard block
 block discarded – undo
518 518
         Event::on(
519 519
             Dashboard::class,
520 520
             Dashboard::EVENT_REGISTER_WIDGET_TYPES,
521
-            function (RegisterComponentTypesEvent $event) {
522
-                $event->types[] = RetourWidget::class;
521
+            function(RegisterComponentTypesEvent $event) {
522
+                $event->types[ ] = RetourWidget::class;
523 523
             }
524 524
         );
525 525
         // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES
526 526
         Event::on(
527 527
             UrlManager::class,
528 528
             UrlManager::EVENT_REGISTER_CP_URL_RULES,
529
-            function (RegisterUrlRulesEvent $event) {
529
+            function(RegisterUrlRulesEvent $event) {
530 530
                 Craft::debug(
531 531
                     'UrlManager::EVENT_REGISTER_CP_URL_RULES',
532 532
                     __METHOD__
@@ -542,13 +542,13 @@  discard block
 block discarded – undo
542 542
         Event::on(
543 543
             UserPermissions::class,
544 544
             UserPermissions::EVENT_REGISTER_PERMISSIONS,
545
-            function (RegisterUserPermissionsEvent $event) {
545
+            function(RegisterUserPermissionsEvent $event) {
546 546
                 Craft::debug(
547 547
                     'UserPermissions::EVENT_REGISTER_PERMISSIONS',
548 548
                     __METHOD__
549 549
                 );
550 550
                 // Register our custom permissions
551
-                $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions();
551
+                $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions();
552 552
             }
553 553
         );
554 554
     }
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
         Event::on(
565 565
             ErrorHandler::class,
566 566
             ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
567
-            function (ExceptionEvent $event) {
567
+            function(ExceptionEvent $event) {
568 568
                 Craft::debug(
569 569
                     'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION',
570 570
                     __METHOD__
@@ -607,16 +607,16 @@  discard block
 block discarded – undo
607 607
     protected function handleElementUriChange(Element $element)
608 608
     {
609 609
         $uris = $this->getAllElementUris($element);
610
-        if (!empty($this->oldElementUris[$element->id])) {
611
-            $oldElementUris = $this->oldElementUris[$element->id];
610
+        if (!empty($this->oldElementUris[ $element->id ])) {
611
+            $oldElementUris = $this->oldElementUris[ $element->id ];
612 612
             foreach ($uris as $siteId => $newUri) {
613
-                if (!empty($oldElementUris[$siteId])) {
614
-                    $oldUri = $oldElementUris[$siteId];
613
+                if (!empty($oldElementUris[ $siteId ])) {
614
+                    $oldUri = $oldElementUris[ $siteId ];
615 615
                     Craft::debug(
616 616
                         Craft::t(
617 617
                             'retour',
618 618
                             'Comparing old: {oldUri} to new: {newUri}',
619
-                            ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)]
619
+                            [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ]
620 620
                         ),
621 621
                         __METHOD__
622 622
                     );
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
                         if (self::$settings->uriChangeRedirectSrcMatch === 'fullurl') {
637 637
                             try {
638 638
                                 if ($redirectSiteId !== null) {
639
-                                    $redirectSiteId = (int)$redirectSiteId;
639
+                                    $redirectSiteId = (int) $redirectSiteId;
640 640
                                 }
641 641
                                 $oldUri = UrlHelper::siteUrl($oldUri, null, null, $redirectSiteId);
642 642
                                 $newUri = UrlHelper::siteUrl($newUri, null, null, $redirectSiteId);
@@ -669,13 +669,13 @@  discard block
 block discarded – undo
669 669
      */
670 670
     protected function getAllElementUris(Element $element): array
671 671
     {
672
-        $uris = [];
672
+        $uris = [ ];
673 673
         if (!self::$craft32 || !ElementHelper::isDraftOrRevision($element)) {
674 674
             $sites = Craft::$app->getSites()->getAllSites();
675 675
             foreach ($sites as $site) {
676 676
                 $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id);
677 677
                 if ($uri !== null) {
678
-                    $uris[$site->id] = $uri;
678
+                    $uris[ $site->id ] = $uri;
679 679
                 }
680 680
             }
681 681
         }
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
             Craft::t(
685 685
                 'retour',
686 686
                 'Getting Element URIs: {uris}',
687
-                ['uris' => print_r($uris, true)]
687
+                [ 'uris' => print_r($uris, true) ]
688 688
             ),
689 689
             __METHOD__
690 690
         );
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
             [
740 740
                 'key' => 'retour-redirect-caches',
741 741
                 'label' => Craft::t('retour', 'Retour redirect caches'),
742
-                'action' => [self::$plugin->redirects, 'invalidateCaches'],
742
+                'action' => [ self::$plugin->redirects, 'invalidateCaches' ],
743 743
             ],
744 744
         ];
745 745
     }
Please login to merge, or discard this patch.