@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | // Protected Properties |
74 | 74 | // ========================================================================= |
75 | 75 | |
76 | - protected $allowAnonymous = []; |
|
76 | + protected $allowAnonymous = [ ]; |
|
77 | 77 | |
78 | 78 | // Public Methods |
79 | 79 | // ========================================================================= |
@@ -115,20 +115,20 @@ discard block |
||
115 | 115 | if ($headers !== null) { |
116 | 116 | $csv->setOffset(1); |
117 | 117 | $columns = ArrayHelper::filterEmptyStringsFromArray($columns); |
118 | - $csv->each(function ($row) use ($headers, $columns) { |
|
118 | + $csv->each(function($row) use ($headers, $columns) { |
|
119 | 119 | $redirectConfig = [ |
120 | 120 | 'id' => 0, |
121 | 121 | ]; |
122 | 122 | $index = 0; |
123 | 123 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
124 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
125 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
124 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
125 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
126 | 126 | ? null |
127 | - : $row[$headers[$columns[$index]]]; |
|
127 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
128 | 128 | } |
129 | 129 | $index++; |
130 | 130 | } |
131 | - Craft::debug('Importing row: '.print_r($redirectConfig, true), __METHOD__); |
|
131 | + Craft::debug('Importing row: ' . print_r($redirectConfig, true), __METHOD__); |
|
132 | 132 | Retour::$plugin->redirects->saveRedirect($redirectConfig); |
133 | 133 | |
134 | 134 | return true; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function actionImportCsv(string $siteHandle = null): Response |
154 | 154 | { |
155 | - $variables = []; |
|
155 | + $variables = [ ]; |
|
156 | 156 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
157 | 157 | // If your CSV document was created or is read on a Macintosh computer, |
158 | 158 | // add the following lines before using the library to help PHP detect line ending in Mac OS X |
@@ -170,38 +170,38 @@ discard block |
||
170 | 170 | } catch (InvalidConfigException $e) { |
171 | 171 | Craft::error($e->getMessage(), __METHOD__); |
172 | 172 | } |
173 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
173 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
174 | 174 | '@nystudio107/retour/assetbundles/retour/dist', |
175 | 175 | true |
176 | 176 | ); |
177 | 177 | // Enabled sites |
178 | 178 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
179 | - $variables['controllerHandle'] = 'file'; |
|
179 | + $variables[ 'controllerHandle' ] = 'file'; |
|
180 | 180 | |
181 | 181 | // Basic variables |
182 | - $variables['fullPageForm'] = true; |
|
183 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
184 | - $variables['pluginName'] = $pluginName; |
|
185 | - $variables['title'] = $templateTitle; |
|
186 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
187 | - $variables['crumbs'] = [ |
|
182 | + $variables[ 'fullPageForm' ] = true; |
|
183 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
184 | + $variables[ 'pluginName' ] = $pluginName; |
|
185 | + $variables[ 'title' ] = $templateTitle; |
|
186 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
187 | + $variables[ 'crumbs' ] = [ |
|
188 | 188 | [ |
189 | 189 | 'label' => $pluginName, |
190 | 190 | 'url' => UrlHelper::cpUrl('retour'), |
191 | 191 | ], |
192 | 192 | [ |
193 | 193 | 'label' => 'Redirects', |
194 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
194 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
195 | 195 | ], |
196 | 196 | ]; |
197 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
198 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
197 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
198 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
199 | 199 | |
200 | 200 | // The CSV file |
201 | 201 | $file = UploadedFile::getInstanceByName('file'); |
202 | 202 | if ($file !== null) { |
203 | 203 | $filename = uniqid($file->name, true); |
204 | - $filePath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$filename; |
|
204 | + $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename; |
|
205 | 205 | $file->saveAs($filePath, false); |
206 | 206 | // Also save the file to the cache as a backup way to access it |
207 | 207 | $cache = Craft::$app->getCache(); |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | $csv = Reader::createFromPath($file->tempName); |
218 | 218 | $headers = $csv->fetchOne(0); |
219 | 219 | Craft::info(print_r($headers, true), __METHOD__); |
220 | - $variables['headers'] = $headers; |
|
221 | - $variables['filename'] = $filePath; |
|
220 | + $variables[ 'headers' ] = $headers; |
|
221 | + $variables[ 'filename' ] = $filePath; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | // Render the template |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | } |
265 | 265 | // Query the db table |
266 | 266 | $data = (new Query()) |
267 | - ->from([$table]) |
|
267 | + ->from([ $table ]) |
|
268 | 268 | ->select(array_keys($columns)) |
269 | 269 | ->orderBy('hitCount DESC') |
270 | 270 | ->all(); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $csv = Writer::createFromFileObject(new \SplTempFileObject()); |
273 | 273 | $csv->insertOne(array_values($columns)); |
274 | 274 | $csv->insertAll($data); |
275 | - $csv->output($filename.'.csv'); |
|
275 | + $csv->output($filename . '.csv'); |
|
276 | 276 | exit(0); |
277 | 277 | } |
278 | 278 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | Craft::t( |
169 | 169 | 'retour', |
170 | 170 | '404 full URL: {fullUrl}, 404 path only: {pathOnly}', |
171 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
171 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
172 | 172 | ), |
173 | 173 | __METHOD__ |
174 | 174 | ); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $response = Craft::$app->getResponse(); |
203 | 203 | if ($redirect !== null) { |
204 | 204 | // Figure out what type of source matching was done |
205 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
205 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
206 | 206 | switch ($redirectSrcMatch) { |
207 | 207 | case 'pathonly': |
208 | 208 | $url = $pathOnly; |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | $url = $pathOnly; |
215 | 215 | break; |
216 | 216 | } |
217 | - $dest = $redirect['redirectDestUrl']; |
|
217 | + $dest = $redirect[ 'redirectDestUrl' ]; |
|
218 | 218 | // If this isn't a full URL, make it one based on the appropriate site |
219 | 219 | if (!UrlHelper::isFullUrl($dest)) { |
220 | 220 | try { |
221 | - $dest = UrlHelper::siteUrl($dest, null, null, $redirect['siteId'] ?? null); |
|
221 | + $dest = UrlHelper::siteUrl($dest, null, null, $redirect[ 'siteId' ] ?? null); |
|
222 | 222 | } catch (\yii\base\Exception $e) { |
223 | 223 | } |
224 | 224 | } |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | $dest .= '?' . $request->getQueryStringWithoutPath(); |
229 | 229 | } |
230 | 230 | } |
231 | - $status = $redirect['redirectHttpCode']; |
|
231 | + $status = $redirect[ 'redirectHttpCode' ]; |
|
232 | 232 | Craft::info( |
233 | 233 | Craft::t( |
234 | 234 | 'retour', |
235 | 235 | 'Redirecting {url} to {dest} with status {status}', |
236 | - ['url' => $url, 'dest' => $dest, 'status' => $status] |
|
236 | + [ 'url' => $url, 'dest' => $dest, 'status' => $status ] |
|
237 | 237 | ), |
238 | 238 | __METHOD__ |
239 | 239 | ); |
@@ -315,13 +315,13 @@ discard block |
||
315 | 315 | public function getRedirectFromCache($url, int $siteId = 0) |
316 | 316 | { |
317 | 317 | $cache = Craft::$app->getCache(); |
318 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
318 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
319 | 319 | $redirect = $cache->get($cacheKey); |
320 | 320 | Craft::info( |
321 | 321 | Craft::t( |
322 | 322 | 'retour', |
323 | 323 | 'Cached redirect hit for {url}', |
324 | - ['url' => $url] |
|
324 | + [ 'url' => $url ] |
|
325 | 325 | ), |
326 | 326 | __METHOD__ |
327 | 327 | ); |
@@ -343,12 +343,12 @@ discard block |
||
343 | 343 | } catch (SiteNotFoundException $e) { |
344 | 344 | $siteId = 1; |
345 | 345 | } |
346 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
346 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
347 | 347 | // Create the dependency tags |
348 | 348 | $dependency = new TagDependency([ |
349 | 349 | 'tags' => [ |
350 | 350 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
351 | - $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
351 | + $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
352 | 352 | ], |
353 | 353 | ]); |
354 | 354 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | Craft::t( |
357 | 357 | 'retour', |
358 | 358 | 'Cached redirect saved for {url}', |
359 | - ['url' => $url] |
|
359 | + [ 'url' => $url ] |
|
360 | 360 | ), |
361 | 361 | __METHOD__ |
362 | 362 | ); |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | // Iterate through the redirects |
387 | 387 | foreach ($redirects as $redirect) { |
388 | 388 | // Figure out what type of source matching to do |
389 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
390 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
389 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
390 | + $redirectEnabled = (bool) $redirect[ 'enabled' ]; |
|
391 | 391 | if ($redirectEnabled === true) { |
392 | 392 | switch ($redirectSrcMatch) { |
393 | 393 | case 'pathonly': |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | $url = $pathOnly; |
401 | 401 | break; |
402 | 402 | } |
403 | - $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
|
403 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound'; |
|
404 | 404 | switch ($redirectMatchType) { |
405 | 405 | // Do a straight up match |
406 | 406 | case 'exactmatch': |
407 | - if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { |
|
407 | + if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) { |
|
408 | 408 | $this->incrementRedirectHitCount($redirect); |
409 | 409 | $this->saveRedirectToCache($url, $redirect); |
410 | 410 | |
@@ -414,14 +414,14 @@ discard block |
||
414 | 414 | |
415 | 415 | // Do a regex match |
416 | 416 | case 'regexmatch': |
417 | - $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
417 | + $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i'; |
|
418 | 418 | if (preg_match($matchRegEx, $url) === 1) { |
419 | 419 | $this->incrementRedirectHitCount($redirect); |
420 | 420 | // If we're not associated with an EntryID, handle capture group replacement |
421 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
422 | - $redirect['redirectDestUrl'] = preg_replace( |
|
421 | + if ((int) $redirect[ 'associatedElementId' ] === 0) { |
|
422 | + $redirect[ 'redirectDestUrl' ] = preg_replace( |
|
423 | 423 | $matchRegEx, |
424 | - $redirect['redirectDestUrl'], |
|
424 | + $redirect[ 'redirectDestUrl' ], |
|
425 | 425 | $url |
426 | 426 | ); |
427 | 427 | } |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | 'redirect' => &$redirect, |
441 | 441 | ], |
442 | 442 | ]; |
443 | - $result = \call_user_func_array([$plugin, 'retourMatch'], $args); |
|
443 | + $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args); |
|
444 | 444 | if ($result) { |
445 | 445 | $this->incrementRedirectHitCount($redirect); |
446 | 446 | $this->saveRedirectToCache($url, $redirect); |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | Craft::t( |
468 | 468 | 'retour', |
469 | 469 | 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}', |
470 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
470 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
471 | 471 | ), |
472 | 472 | __METHOD__ |
473 | 473 | ); |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
513 | 513 | /** @var Plugin $plugin */ |
514 | 514 | if (method_exists($plugin, 'retourMatch')) { |
515 | - $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
515 | + $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match'); |
|
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
@@ -533,12 +533,12 @@ discard block |
||
533 | 533 | } |
534 | 534 | // Query the db table |
535 | 535 | $query = (new Query()) |
536 | - ->from(['{{%retour_static_redirects}}']) |
|
536 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
537 | 537 | ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC'); |
538 | 538 | if ($siteId) { |
539 | 539 | $query |
540 | - ->where(['siteId' => $siteId]) |
|
541 | - ->orWhere(['siteId' => null]); |
|
540 | + ->where([ 'siteId' => $siteId ]) |
|
541 | + ->orWhere([ 'siteId' => null ]); |
|
542 | 542 | } |
543 | 543 | if ($limit) { |
544 | 544 | $query->limit($limit); |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | { |
562 | 562 | // Query the db table |
563 | 563 | $redirect = (new Query()) |
564 | - ->from(['{{%retour_static_redirects}}']) |
|
565 | - ->where(['id' => $id]) |
|
564 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
565 | + ->where([ 'id' => $id ]) |
|
566 | 566 | ->one(); |
567 | 567 | |
568 | 568 | return $redirect; |
@@ -580,16 +580,16 @@ discard block |
||
580 | 580 | { |
581 | 581 | // Query the db table |
582 | 582 | $query = (new Query()) |
583 | - ->from(['{{%retour_static_redirects}}']) |
|
584 | - ->where(['redirectSrcUrl' => $redirectSrcUrl]) |
|
583 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
584 | + ->where([ 'redirectSrcUrl' => $redirectSrcUrl ]) |
|
585 | 585 | ; |
586 | 586 | if ($siteId) { |
587 | 587 | $query |
588 | - ->andWhere(['or', [ |
|
588 | + ->andWhere([ 'or', [ |
|
589 | 589 | 'siteId' => $siteId, |
590 | 590 | ], [ |
591 | 591 | 'siteId' => null, |
592 | - ]]); |
|
592 | + ] ]); |
|
593 | 593 | } |
594 | 594 | $redirect = $query->one(); |
595 | 595 | |
@@ -631,13 +631,13 @@ discard block |
||
631 | 631 | { |
632 | 632 | if ($redirectConfig !== null) { |
633 | 633 | $db = Craft::$app->getDb(); |
634 | - $redirectConfig['hitCount']++; |
|
635 | - $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime()); |
|
634 | + $redirectConfig[ 'hitCount' ]++; |
|
635 | + $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime()); |
|
636 | 636 | Craft::debug( |
637 | 637 | Craft::t( |
638 | 638 | 'retour', |
639 | 639 | 'Incrementing statistics for: {redirect}', |
640 | - ['redirect' => print_r($redirectConfig, true)] |
|
640 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
641 | 641 | ), |
642 | 642 | __METHOD__ |
643 | 643 | ); |
@@ -646,14 +646,14 @@ discard block |
||
646 | 646 | $rowsAffected = $db->createCommand()->update( |
647 | 647 | '{{%retour_static_redirects}}', |
648 | 648 | [ |
649 | - 'hitCount' => $redirectConfig['hitCount'], |
|
650 | - 'hitLastTime' => $redirectConfig['hitLastTime'], |
|
649 | + 'hitCount' => $redirectConfig[ 'hitCount' ], |
|
650 | + 'hitLastTime' => $redirectConfig[ 'hitLastTime' ], |
|
651 | 651 | ], |
652 | 652 | [ |
653 | - 'id' => $redirectConfig['id'], |
|
653 | + 'id' => $redirectConfig[ 'id' ], |
|
654 | 654 | ] |
655 | 655 | )->execute(); |
656 | - Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
656 | + Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
657 | 657 | } catch (\Exception $e) { |
658 | 658 | Craft::error($e->getMessage(), __METHOD__); |
659 | 659 | } |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | Craft::t( |
673 | 673 | 'retour', |
674 | 674 | 'Error validating redirect {id}: {errors}', |
675 | - ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)] |
|
675 | + [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ] |
|
676 | 676 | ), |
677 | 677 | __METHOD__ |
678 | 678 | ); |
@@ -682,32 +682,32 @@ discard block |
||
682 | 682 | // Get the validated model attributes and save them to the db |
683 | 683 | $redirectConfig = $redirect->getAttributes(); |
684 | 684 | // 0 for a siteId needs to be converted to null |
685 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
686 | - $redirectConfig['siteId'] = null; |
|
685 | + if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) { |
|
686 | + $redirectConfig[ 'siteId' ] = null; |
|
687 | 687 | } |
688 | 688 | // Throw an event to before saving the redirect |
689 | 689 | $db = Craft::$app->getDb(); |
690 | 690 | // See if a redirect exists with this source URL already |
691 | - if ((int)$redirectConfig['id'] === 0) { |
|
691 | + if ((int) $redirectConfig[ 'id' ] === 0) { |
|
692 | 692 | // Query the db table |
693 | 693 | $redirect = (new Query()) |
694 | - ->from(['{{%retour_static_redirects}}']) |
|
695 | - ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']]) |
|
696 | - ->andWhere(['siteId' => $redirectConfig['siteId']]) |
|
694 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
695 | + ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ]) |
|
696 | + ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ]) |
|
697 | 697 | ->one(); |
698 | 698 | // If it exists, update it rather than having duplicates |
699 | 699 | if (!empty($redirect)) { |
700 | - $redirectConfig['id'] = $redirect['id']; |
|
700 | + $redirectConfig[ 'id' ] = $redirect[ 'id' ]; |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | // Trigger a 'beforeSaveRedirect' event |
704 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
704 | + $isNew = (int) $redirectConfig[ 'id' ] === 0; |
|
705 | 705 | $event = new RedirectEvent([ |
706 | 706 | 'isNew' => $isNew, |
707 | - 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
|
708 | - 'destinationUrl' => $redirectConfig['redirectDestUrl'], |
|
709 | - 'matchType' => $redirectConfig['redirectSrcMatch'], |
|
710 | - 'redirectType' => $redirectConfig['redirectHttpCode'], |
|
707 | + 'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ], |
|
708 | + 'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ], |
|
709 | + 'matchType' => $redirectConfig[ 'redirectSrcMatch' ], |
|
710 | + 'redirectType' => $redirectConfig[ 'redirectHttpCode' ], |
|
711 | 711 | ]); |
712 | 712 | $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event); |
713 | 713 | if (!$event->isValid) { |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | Craft::t( |
720 | 720 | 'retour', |
721 | 721 | 'Updating existing redirect: {redirect}', |
722 | - ['redirect' => print_r($redirectConfig, true)] |
|
722 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
723 | 723 | ), |
724 | 724 | __METHOD__ |
725 | 725 | ); |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | '{{%retour_static_redirects}}', |
730 | 730 | $redirectConfig, |
731 | 731 | [ |
732 | - 'id' => $redirectConfig['id'], |
|
732 | + 'id' => $redirectConfig[ 'id' ], |
|
733 | 733 | ] |
734 | 734 | )->execute(); |
735 | 735 | } catch (Exception $e) { |
@@ -740,11 +740,11 @@ discard block |
||
740 | 740 | Craft::t( |
741 | 741 | 'retour', |
742 | 742 | 'Creating new redirect: {redirect}', |
743 | - ['redirect' => print_r($redirectConfig, true)] |
|
743 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
744 | 744 | ), |
745 | 745 | __METHOD__ |
746 | 746 | ); |
747 | - unset($redirectConfig['id']); |
|
747 | + unset($redirectConfig[ 'id' ]); |
|
748 | 748 | // Create a new record |
749 | 749 | try { |
750 | 750 | $db->createCommand()->insert( |
@@ -757,15 +757,15 @@ discard block |
||
757 | 757 | } |
758 | 758 | // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl |
759 | 759 | $testRedirectConfig = $this->getRedirectByRedirectSrcUrl( |
760 | - $redirectConfig['redirectDestUrl'], |
|
761 | - $redirectConfig['siteId'] |
|
760 | + $redirectConfig[ 'redirectDestUrl' ], |
|
761 | + $redirectConfig[ 'siteId' ] |
|
762 | 762 | ); |
763 | 763 | if ($testRedirectConfig !== null) { |
764 | 764 | Craft::debug( |
765 | 765 | Craft::t( |
766 | 766 | 'retour', |
767 | 767 | 'Deleting redirect to prevent a loop: {redirect}', |
768 | - ['redirect' => print_r($testRedirectConfig, true)] |
|
768 | + [ 'redirect' => print_r($testRedirectConfig, true) ] |
|
769 | 769 | ), |
770 | 770 | __METHOD__ |
771 | 771 | ); |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | try { |
774 | 774 | $db->createCommand()->delete( |
775 | 775 | '{{%retour_static_redirects}}', |
776 | - ['id' => $testRedirectConfig['id']] |
|
776 | + [ 'id' => $testRedirectConfig[ 'id' ] ] |
|
777 | 777 | )->execute(); |
778 | 778 | } catch (Exception $e) { |
779 | 779 | Craft::error($e->getMessage(), __METHOD__); |
@@ -806,10 +806,10 @@ discard block |
||
806 | 806 | */ |
807 | 807 | public function excludeUri($uri): bool |
808 | 808 | { |
809 | - $uri = '/'.ltrim($uri, '/'); |
|
809 | + $uri = '/' . ltrim($uri, '/'); |
|
810 | 810 | if (!empty(Retour::$settings->excludePatterns)) { |
811 | 811 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
812 | - $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
812 | + $pattern = '`' . $excludePattern[ 'pattern' ] . '`i'; |
|
813 | 813 | if (preg_match($pattern, $uri) === 1) { |
814 | 814 | return true; |
815 | 815 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | public function rules() |
125 | 125 | { |
126 | 126 | return [ |
127 | - ['pluginName', 'string'], |
|
128 | - ['pluginName', 'default', 'value' => 'Retour'], |
|
127 | + [ 'pluginName', 'string' ], |
|
128 | + [ 'pluginName', 'default', 'value' => 'Retour' ], |
|
129 | 129 | [ |
130 | 130 | [ |
131 | 131 | 'createUriChangeRedirects', |
@@ -136,23 +136,23 @@ discard block |
||
136 | 136 | ], |
137 | 137 | 'boolean', |
138 | 138 | ], |
139 | - ['uriChangeRedirectSrcMatch', 'default', 'value' => 'pathonly'], |
|
140 | - ['uriChangeRedirectSrcMatch', 'string'], |
|
141 | - ['uriChangeRedirectSrcMatch', 'in', 'range' => [ |
|
139 | + [ 'uriChangeRedirectSrcMatch', 'default', 'value' => 'pathonly' ], |
|
140 | + [ 'uriChangeRedirectSrcMatch', 'string' ], |
|
141 | + [ 'uriChangeRedirectSrcMatch', 'in', 'range' => [ |
|
142 | 142 | 'pathonly', |
143 | 143 | 'fullurl' |
144 | - ]], |
|
145 | - ['staticRedirectDisplayLimit', 'integer', 'min' => 1], |
|
146 | - ['staticRedirectDisplayLimit', 'default', 'value' => 100], |
|
147 | - ['dynamicRedirectDisplayLimit', 'integer', 'min' => 1], |
|
148 | - ['dynamicRedirectDisplayLimit', 'default', 'value' => 100], |
|
149 | - ['statsStoredLimit', 'integer', 'min' => 1], |
|
150 | - ['statsStoredLimit', 'default', 'value' => 1000], |
|
151 | - ['refreshIntervalSecs', 'integer', 'min' => 0], |
|
152 | - ['refreshIntervalSecs', 'default', 'value' => 3], |
|
153 | - ['statsDisplayLimit', 'integer', 'min' => 1], |
|
154 | - ['statsDisplayLimit', 'default', 'value' => 1000], |
|
155 | - ['excludePatterns', ArrayValidator::class], |
|
144 | + ] ], |
|
145 | + [ 'staticRedirectDisplayLimit', 'integer', 'min' => 1 ], |
|
146 | + [ 'staticRedirectDisplayLimit', 'default', 'value' => 100 ], |
|
147 | + [ 'dynamicRedirectDisplayLimit', 'integer', 'min' => 1 ], |
|
148 | + [ 'dynamicRedirectDisplayLimit', 'default', 'value' => 100 ], |
|
149 | + [ 'statsStoredLimit', 'integer', 'min' => 1 ], |
|
150 | + [ 'statsStoredLimit', 'default', 'value' => 1000 ], |
|
151 | + [ 'refreshIntervalSecs', 'integer', 'min' => 0 ], |
|
152 | + [ 'refreshIntervalSecs', 'default', 'value' => 3 ], |
|
153 | + [ 'statsDisplayLimit', 'integer', 'min' => 1 ], |
|
154 | + [ 'statsDisplayLimit', 'default', 'value' => 1000 ], |
|
155 | + [ 'excludePatterns', ArrayValidator::class ], |
|
156 | 156 | ]; |
157 | 157 | } |
158 | 158 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function behaviors() |
163 | 163 | { |
164 | - $craft31Behaviors = []; |
|
164 | + $craft31Behaviors = [ ]; |
|
165 | 165 | if (Retour::$craft31) { |
166 | 166 | $craft31Behaviors = [ |
167 | 167 | 'parser' => [ |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $siteId = 0 |
64 | 64 | ): Response { |
65 | 65 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
66 | - $data = []; |
|
66 | + $data = [ ]; |
|
67 | 67 | $sortField = 'hitCount'; |
68 | 68 | $sortType = 'DESC'; |
69 | 69 | // Figure out the sorting type |
@@ -77,42 +77,42 @@ discard block |
||
77 | 77 | // Query the db table |
78 | 78 | $offset = ($page - 1) * $per_page; |
79 | 79 | $query = (new Query()) |
80 | - ->from(['{{%retour_stats}}']) |
|
80 | + ->from([ '{{%retour_stats}}' ]) |
|
81 | 81 | ->offset($offset) |
82 | 82 | ->limit($per_page) |
83 | 83 | ->orderBy("{$sortField} {$sortType}"); |
84 | - if ((int)$siteId !== 0) { |
|
85 | - $query->where(['siteId' => $siteId]); |
|
84 | + if ((int) $siteId !== 0) { |
|
85 | + $query->where([ 'siteId' => $siteId ]); |
|
86 | 86 | } |
87 | 87 | if ($filter !== '') { |
88 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
89 | - $query->orWhere(['like', 'referrerUrl', $filter]); |
|
88 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
89 | + $query->orWhere([ 'like', 'referrerUrl', $filter ]); |
|
90 | 90 | } |
91 | 91 | $stats = $query->all(); |
92 | 92 | if ($stats) { |
93 | 93 | // Add in the `addLink` field |
94 | 94 | foreach ($stats as &$stat) { |
95 | - $stat['addLink'] = ''; |
|
96 | - if (!$stat['handledByRetour']) { |
|
97 | - $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/')); |
|
98 | - $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
95 | + $stat[ 'addLink' ] = ''; |
|
96 | + if (!$stat[ 'handledByRetour' ]) { |
|
97 | + $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/')); |
|
98 | + $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
99 | 99 | 'defaultUrl' => $encodedUrl |
100 | 100 | ]); |
101 | 101 | } |
102 | 102 | } |
103 | 103 | // Format the data for the API |
104 | - $data['data'] = $stats; |
|
104 | + $data[ 'data' ] = $stats; |
|
105 | 105 | $query = (new Query()) |
106 | - ->from(['{{%retour_stats}}']); |
|
107 | - if ((int)$siteId !== 0) { |
|
108 | - $query->where(['siteId' => $siteId]); |
|
106 | + ->from([ '{{%retour_stats}}' ]); |
|
107 | + if ((int) $siteId !== 0) { |
|
108 | + $query->where([ 'siteId' => $siteId ]); |
|
109 | 109 | } |
110 | 110 | if ($filter !== '') { |
111 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
112 | - $query->orWhere(['like', 'referrerUrl', $filter]); |
|
111 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
112 | + $query->orWhere([ 'like', 'referrerUrl', $filter ]); |
|
113 | 113 | } |
114 | 114 | $count = $query->count(); |
115 | - $data['links']['pagination'] = [ |
|
115 | + $data[ 'links' ][ 'pagination' ] = [ |
|
116 | 116 | 'total' => $count, |
117 | 117 | 'per_page' => $per_page, |
118 | 118 | 'current_page' => $page, |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $siteId = 0 |
148 | 148 | ): Response { |
149 | 149 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
150 | - $data = []; |
|
150 | + $data = [ ]; |
|
151 | 151 | $sortField = 'hitCount'; |
152 | 152 | $sortType = 'DESC'; |
153 | 153 | // Figure out the sorting type |
@@ -161,53 +161,53 @@ discard block |
||
161 | 161 | // Query the db table |
162 | 162 | $offset = ($page - 1) * $per_page; |
163 | 163 | $query = (new Query()) |
164 | - ->from(['{{%retour_static_redirects}}']) |
|
164 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
165 | 165 | ->offset($offset) |
166 | 166 | ->limit($per_page) |
167 | 167 | ->orderBy("{$sortField} {$sortType}"); |
168 | - if ((int)$siteId !== 0) { |
|
169 | - $query->where(['siteId' => $siteId]); |
|
168 | + if ((int) $siteId !== 0) { |
|
169 | + $query->where([ 'siteId' => $siteId ]); |
|
170 | 170 | } |
171 | 171 | if ($filter !== '') { |
172 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
173 | - $query->orWhere(['like', 'redirectDestUrl', $filter]); |
|
172 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
173 | + $query->orWhere([ 'like', 'redirectDestUrl', $filter ]); |
|
174 | 174 | } |
175 | 175 | $redirects = $query->all(); |
176 | 176 | // Add in the `deleteLink` field and clean up the redirects |
177 | 177 | foreach ($redirects as &$redirect) { |
178 | 178 | // Make sure the destination URL is not a regex |
179 | - if ($redirect['redirectMatchType'] !== 'exactmatch') { |
|
180 | - if (preg_match("/\$\d+/", $redirect['redirectDestUrl'])) { |
|
181 | - $redirect['redirectDestUrl'] = ''; |
|
179 | + if ($redirect[ 'redirectMatchType' ] !== 'exactmatch') { |
|
180 | + if (preg_match("/\$\d+/", $redirect[ 'redirectDestUrl' ])) { |
|
181 | + $redirect[ 'redirectDestUrl' ] = ''; |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | // Handle extracting the site name |
185 | - $redirect['siteName'] = Craft::t('retour', 'All Sites'); |
|
186 | - if ($redirect['siteId']) { |
|
185 | + $redirect[ 'siteName' ] = Craft::t('retour', 'All Sites'); |
|
186 | + if ($redirect[ 'siteId' ]) { |
|
187 | 187 | $sites = Craft::$app->getSites(); |
188 | - $site = $sites->getSiteById($redirect['siteId']); |
|
188 | + $site = $sites->getSiteById($redirect[ 'siteId' ]); |
|
189 | 189 | if ($site) { |
190 | - $redirect['siteName'] = $site->name; |
|
190 | + $redirect[ 'siteName' ] = $site->name; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - $redirect['deleteLink'] = UrlHelper::cpUrl('retour/delete-redirect/'.$redirect['id']); |
|
195 | - $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']); |
|
194 | + $redirect[ 'deleteLink' ] = UrlHelper::cpUrl('retour/delete-redirect/' . $redirect[ 'id' ]); |
|
195 | + $redirect[ 'editLink' ] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]); |
|
196 | 196 | } |
197 | 197 | // Format the data for the API |
198 | 198 | if ($redirects) { |
199 | - $data['data'] = $redirects; |
|
199 | + $data[ 'data' ] = $redirects; |
|
200 | 200 | $query = (new Query()) |
201 | - ->from(['{{%retour_static_redirects}}']); |
|
202 | - if ((int)$siteId !== 0) { |
|
203 | - $query->where(['siteId' => $siteId]); |
|
201 | + ->from([ '{{%retour_static_redirects}}' ]); |
|
202 | + if ((int) $siteId !== 0) { |
|
203 | + $query->where([ 'siteId' => $siteId ]); |
|
204 | 204 | } |
205 | 205 | if ($filter !== '') { |
206 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
207 | - $query->orWhere(['like', 'redirectDestUrl', $filter]); |
|
206 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
207 | + $query->orWhere([ 'like', 'redirectDestUrl', $filter ]); |
|
208 | 208 | } |
209 | 209 | $count = $query->count(); |
210 | - $data['links']['pagination'] = [ |
|
210 | + $data[ 'links' ][ 'pagination' ] = [ |
|
211 | 211 | 'total' => $count, |
212 | 212 | 'per_page' => $per_page, |
213 | 213 | 'current_page' => $page, |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | /** |
122 | 122 | * @var array The URIs for the element before it was saved |
123 | 123 | */ |
124 | - public $oldElementUris = []; |
|
124 | + public $oldElementUris = [ ]; |
|
125 | 125 | |
126 | 126 | // Public Methods |
127 | 127 | // ========================================================================= |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | Craft::t( |
155 | 155 | 'retour', |
156 | 156 | '{name} plugin loaded', |
157 | - ['name' => $this->name] |
|
157 | + [ 'name' => $this->name ] |
|
158 | 158 | ), |
159 | 159 | __METHOD__ |
160 | 160 | ); |
@@ -174,18 +174,18 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function getCpNavItem() |
176 | 176 | { |
177 | - $subNavs = []; |
|
177 | + $subNavs = [ ]; |
|
178 | 178 | $navItem = parent::getCpNavItem(); |
179 | 179 | $currentUser = Craft::$app->getUser()->getIdentity(); |
180 | 180 | // Only show sub-navs the user has permission to view |
181 | 181 | if ($currentUser->can('retour:dashboard')) { |
182 | - $subNavs['dashboard'] = [ |
|
182 | + $subNavs[ 'dashboard' ] = [ |
|
183 | 183 | 'label' => 'Dashboard', |
184 | 184 | 'url' => 'retour/dashboard', |
185 | 185 | ]; |
186 | 186 | } |
187 | 187 | if ($currentUser->can('retour:redirects')) { |
188 | - $subNavs['redirects'] = [ |
|
188 | + $subNavs[ 'redirects' ] = [ |
|
189 | 189 | 'label' => 'Redirects', |
190 | 190 | 'url' => 'retour/redirects', |
191 | 191 | ]; |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $editableSettings = false; |
197 | 197 | } |
198 | 198 | if ($currentUser->can('retour:settings') && $editableSettings) { |
199 | - $subNavs['settings'] = [ |
|
199 | + $subNavs[ 'settings' ] = [ |
|
200 | 200 | 'label' => 'Settings', |
201 | 201 | 'url' => 'retour/settings', |
202 | 202 | ]; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | Event::on( |
256 | 256 | ClearCaches::class, |
257 | 257 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
258 | - function (RegisterCacheOptionsEvent $event) { |
|
258 | + function(RegisterCacheOptionsEvent $event) { |
|
259 | 259 | Craft::debug( |
260 | 260 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
261 | 261 | __METHOD__ |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | Event::on( |
272 | 272 | Plugins::class, |
273 | 273 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
274 | - function (PluginEvent $event) { |
|
274 | + function(PluginEvent $event) { |
|
275 | 275 | if ($event->plugin === $this) { |
276 | 276 | // Invalidate our caches after we've been installed |
277 | 277 | $this->clearAllCaches(); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | Event::on( |
299 | 299 | CraftVariable::class, |
300 | 300 | CraftVariable::EVENT_INIT, |
301 | - function (Event $event) { |
|
301 | + function(Event $event) { |
|
302 | 302 | /** @var CraftVariable $variable */ |
303 | 303 | $variable = $event->sender; |
304 | 304 | $variable->set('retour', RetourVariable::class); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | Event::on( |
309 | 309 | Elements::class, |
310 | 310 | Elements::EVENT_BEFORE_SAVE_ELEMENT, |
311 | - function (ElementEvent $event) { |
|
311 | + function(ElementEvent $event) { |
|
312 | 312 | Craft::debug( |
313 | 313 | 'Elements::EVENT_BEFORE_SAVE_ELEMENT', |
314 | 314 | __METHOD__ |
@@ -333,8 +333,8 @@ discard block |
||
333 | 333 | if (strpos($element->uri, '__temp_') === false && !$element->propagating) { |
334 | 334 | // Stash the old URLs by element id, and do so only once, |
335 | 335 | // in case we are called more than once per request |
336 | - if (empty($this->oldElementUris[$element->id])) { |
|
337 | - $this->oldElementUris[$element->id] = $this->getAllElementUris($element); |
|
336 | + if (empty($this->oldElementUris[ $element->id ])) { |
|
337 | + $this->oldElementUris[ $element->id ] = $this->getAllElementUris($element); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | Event::on( |
346 | 346 | Elements::class, |
347 | 347 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
348 | - function (ElementEvent $event) { |
|
348 | + function(ElementEvent $event) { |
|
349 | 349 | Craft::debug( |
350 | 350 | 'Elements::EVENT_AFTER_SAVE_ELEMENT', |
351 | 351 | __METHOD__ |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | Event::on( |
368 | 368 | Plugins::class, |
369 | 369 | Plugins::EVENT_AFTER_LOAD_PLUGINS, |
370 | - function () { |
|
370 | + function() { |
|
371 | 371 | // Install these only after all other plugins have loaded |
372 | 372 | $request = Craft::$app->getRequest(); |
373 | 373 | // Only respond to non-console site requests |
@@ -385,26 +385,26 @@ discard block |
||
385 | 385 | Event::on( |
386 | 386 | Gql::class, |
387 | 387 | Gql::EVENT_REGISTER_GQL_TYPES, |
388 | - function (RegisterGqlTypesEvent $event) { |
|
388 | + function(RegisterGqlTypesEvent $event) { |
|
389 | 389 | Craft::debug( |
390 | 390 | 'Gql::EVENT_REGISTER_GQL_TYPES', |
391 | 391 | __METHOD__ |
392 | 392 | ); |
393 | - $event->types[] = RetourInterface::class; |
|
393 | + $event->types[ ] = RetourInterface::class; |
|
394 | 394 | } |
395 | 395 | ); |
396 | 396 | // Handler: Gql::EVENT_REGISTER_GQL_QUERIES |
397 | 397 | Event::on( |
398 | 398 | Gql::class, |
399 | 399 | Gql::EVENT_REGISTER_GQL_QUERIES, |
400 | - function (RegisterGqlQueriesEvent $event) { |
|
400 | + function(RegisterGqlQueriesEvent $event) { |
|
401 | 401 | Craft::debug( |
402 | 402 | 'Gql::EVENT_REGISTER_GQL_QUERIES', |
403 | 403 | __METHOD__ |
404 | 404 | ); |
405 | 405 | $queries = RetourQuery::getQueries(); |
406 | 406 | foreach ($queries as $key => $value) { |
407 | - $event->queries[$key] = $value; |
|
407 | + $event->queries[ $key ] = $value; |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | ); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | Event::on( |
415 | 415 | Schema::class, |
416 | 416 | AlterSchemaFields::EVENT, |
417 | - [GetCraftQLSchema::class, 'handle'] |
|
417 | + [ GetCraftQLSchema::class, 'handle' ] |
|
418 | 418 | ); |
419 | 419 | } |
420 | 420 | } |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | Event::on( |
429 | 429 | UrlManager::class, |
430 | 430 | UrlManager::EVENT_REGISTER_SITE_URL_RULES, |
431 | - function (RegisterUrlRulesEvent $event) { |
|
431 | + function(RegisterUrlRulesEvent $event) { |
|
432 | 432 | Craft::debug( |
433 | 433 | 'UrlManager::EVENT_REGISTER_SITE_URL_RULES', |
434 | 434 | __METHOD__ |
@@ -451,15 +451,15 @@ discard block |
||
451 | 451 | Event::on( |
452 | 452 | Dashboard::class, |
453 | 453 | Dashboard::EVENT_REGISTER_WIDGET_TYPES, |
454 | - function (RegisterComponentTypesEvent $event) { |
|
455 | - $event->types[] = RetourWidget::class; |
|
454 | + function(RegisterComponentTypesEvent $event) { |
|
455 | + $event->types[ ] = RetourWidget::class; |
|
456 | 456 | } |
457 | 457 | ); |
458 | 458 | // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES |
459 | 459 | Event::on( |
460 | 460 | UrlManager::class, |
461 | 461 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
462 | - function (RegisterUrlRulesEvent $event) { |
|
462 | + function(RegisterUrlRulesEvent $event) { |
|
463 | 463 | Craft::debug( |
464 | 464 | 'UrlManager::EVENT_REGISTER_CP_URL_RULES', |
465 | 465 | __METHOD__ |
@@ -475,13 +475,13 @@ discard block |
||
475 | 475 | Event::on( |
476 | 476 | UserPermissions::class, |
477 | 477 | UserPermissions::EVENT_REGISTER_PERMISSIONS, |
478 | - function (RegisterUserPermissionsEvent $event) { |
|
478 | + function(RegisterUserPermissionsEvent $event) { |
|
479 | 479 | Craft::debug( |
480 | 480 | 'UserPermissions::EVENT_REGISTER_PERMISSIONS', |
481 | 481 | __METHOD__ |
482 | 482 | ); |
483 | 483 | // Register our custom permissions |
484 | - $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions(); |
|
484 | + $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions(); |
|
485 | 485 | } |
486 | 486 | ); |
487 | 487 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | Event::on( |
498 | 498 | ErrorHandler::class, |
499 | 499 | ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION, |
500 | - function (ExceptionEvent $event) { |
|
500 | + function(ExceptionEvent $event) { |
|
501 | 501 | Craft::debug( |
502 | 502 | 'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION', |
503 | 503 | __METHOD__ |
@@ -540,16 +540,16 @@ discard block |
||
540 | 540 | protected function handleElementUriChange(Element $element) |
541 | 541 | { |
542 | 542 | $uris = $this->getAllElementUris($element); |
543 | - if (!empty($this->oldElementUris[$element->id])) { |
|
544 | - $oldElementUris = $this->oldElementUris[$element->id]; |
|
543 | + if (!empty($this->oldElementUris[ $element->id ])) { |
|
544 | + $oldElementUris = $this->oldElementUris[ $element->id ]; |
|
545 | 545 | foreach ($uris as $siteId => $newUri) { |
546 | - if (!empty($oldElementUris[$siteId])) { |
|
547 | - $oldUri = $oldElementUris[$siteId]; |
|
546 | + if (!empty($oldElementUris[ $siteId ])) { |
|
547 | + $oldUri = $oldElementUris[ $siteId ]; |
|
548 | 548 | Craft::debug( |
549 | 549 | Craft::t( |
550 | 550 | 'retour', |
551 | 551 | 'Comparing old: {oldUri} to new: {newUri}', |
552 | - ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)] |
|
552 | + [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ] |
|
553 | 553 | ), |
554 | 554 | __METHOD__ |
555 | 555 | ); |
@@ -599,13 +599,13 @@ discard block |
||
599 | 599 | */ |
600 | 600 | protected function getAllElementUris(Element $element): array |
601 | 601 | { |
602 | - $uris = []; |
|
602 | + $uris = [ ]; |
|
603 | 603 | if (!self::$craft32 || !ElementHelper::isDraftOrRevision($element)) { |
604 | 604 | $sites = Craft::$app->getSites()->getAllSites(); |
605 | 605 | foreach ($sites as $site) { |
606 | 606 | $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id); |
607 | 607 | if ($uri !== null) { |
608 | - $uris[$site->id] = $uri; |
|
608 | + $uris[ $site->id ] = $uri; |
|
609 | 609 | } |
610 | 610 | } |
611 | 611 | } |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | Craft::t( |
615 | 615 | 'retour', |
616 | 616 | 'Getting Element URIs: {uris}', |
617 | - ['uris' => print_r($uris, true)] |
|
617 | + [ 'uris' => print_r($uris, true) ] |
|
618 | 618 | ), |
619 | 619 | __METHOD__ |
620 | 620 | ); |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | [ |
672 | 672 | 'key' => 'retour-redirect-caches', |
673 | 673 | 'label' => Craft::t('retour', 'Retour redirect caches'), |
674 | - 'action' => [self::$plugin->redirects, 'invalidateCaches'], |
|
674 | + 'action' => [ self::$plugin->redirects, 'invalidateCaches' ], |
|
675 | 675 | ], |
676 | 676 | ]; |
677 | 677 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct(array $config) |
33 | 33 | { |
34 | - $config['interfaces'] = [ |
|
34 | + $config[ 'interfaces' ] = [ |
|
35 | 35 | RetourInterface::getType(), |
36 | 36 | ]; |
37 | 37 | |
@@ -45,6 +45,6 @@ discard block |
||
45 | 45 | { |
46 | 46 | $fieldName = $resolveInfo->fieldName; |
47 | 47 | |
48 | - return $source[$fieldName]; |
|
48 | + return $source[ $fieldName ]; |
|
49 | 49 | } |
50 | 50 | } |
@@ -40,20 +40,20 @@ |
||
40 | 40 | $retourType = GqlEntityRegistry::getEntity($typeName) |
41 | 41 | ?: GqlEntityRegistry::createEntity($typeName, new RetourType([ |
42 | 42 | 'name' => $typeName, |
43 | - 'args' => function () use ($retourArgs) { |
|
43 | + 'args' => function() use ($retourArgs) { |
|
44 | 44 | return $retourArgs; |
45 | 45 | }, |
46 | - 'fields' => function () use ($retourFields) { |
|
46 | + 'fields' => function() use ($retourFields) { |
|
47 | 47 | return $retourFields; |
48 | 48 | }, |
49 | 49 | 'description' => 'This entity has all the Retour fields', |
50 | 50 | ])); |
51 | 51 | |
52 | - TypeLoader::registerType($typeName, function () use ($retourType) { |
|
52 | + TypeLoader::registerType($typeName, function() use ($retourType) { |
|
53 | 53 | return $retourType; |
54 | 54 | }); |
55 | 55 | |
56 | - return [$retourType]; |
|
56 | + return [ $retourType ]; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -48,15 +48,15 @@ |
||
48 | 48 | |
49 | 49 | $type = GqlEntityRegistry::createEntity(self::class, new InterfaceType([ |
50 | 50 | 'name' => static::getName(), |
51 | - 'fields' => self::class.'::getFieldDefinitions', |
|
51 | + 'fields' => self::class . '::getFieldDefinitions', |
|
52 | 52 | 'description' => 'This is the interface implemented by Retour.', |
53 | - 'resolveType' => function (array $value) { |
|
53 | + 'resolveType' => function(array $value) { |
|
54 | 54 | return GqlEntityRegistry::getEntity(RetourGenerator::getName()); |
55 | 55 | }, |
56 | 56 | ])); |
57 | 57 | |
58 | 58 | foreach (RetourGenerator::generateTypes() as $typeName => $generatedType) { |
59 | - TypeLoader::registerType($typeName, function () use ($generatedType) { |
|
59 | + TypeLoader::registerType($typeName, function() use ($generatedType) { |
|
60 | 60 | return $generatedType; |
61 | 61 | }); |
62 | 62 | } |
@@ -40,8 +40,8 @@ |
||
40 | 40 | $siteId = $source->siteId; |
41 | 41 | } else { |
42 | 42 | // Otherwise use the passed in arguments, or defaults |
43 | - $uri = $arguments['uri'] ?? '/'; |
|
44 | - $siteId = $arguments['siteId'] ?? null; |
|
43 | + $uri = $arguments[ 'uri' ] ?? '/'; |
|
44 | + $siteId = $arguments[ 'siteId' ] ?? null; |
|
45 | 45 | } |
46 | 46 | $uri = trim($uri === '/' ? '__home__' : $uri); |
47 | 47 |