@@ -40,7 +40,7 @@ discard block |
||
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 |
||
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,34 +71,34 @@ discard block |
||
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'] = 'dashboard'; |
|
80 | + $variables[ 'controllerHandle' ] = 'dashboard'; |
|
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 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
88 | - $variables['crumbs'] = [ |
|
83 | + $variables[ 'fullPageForm' ] = false; |
|
84 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
85 | + $variables[ 'pluginName' ] = $pluginName; |
|
86 | + $variables[ 'title' ] = $templateTitle; |
|
87 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
88 | + $variables[ 'crumbs' ] = [ |
|
89 | 89 | [ |
90 | 90 | 'label' => $pluginName, |
91 | 91 | 'url' => UrlHelper::cpUrl('retour'), |
92 | 92 | ], |
93 | 93 | [ |
94 | 94 | 'label' => $templateTitle, |
95 | - 'url' => UrlHelper::cpUrl('retour/dashboard'.$siteHandleUri), |
|
95 | + 'url' => UrlHelper::cpUrl('retour/dashboard' . $siteHandleUri), |
|
96 | 96 | ], |
97 | 97 | ]; |
98 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
99 | - $variables['selectedSubnavItem'] = 'dashboard'; |
|
100 | - $variables['showWelcome'] = $showWelcome; |
|
101 | - $variables['settings'] = Retour::$settings; |
|
98 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
99 | + $variables[ 'selectedSubnavItem' ] = 'dashboard'; |
|
100 | + $variables[ 'showWelcome' ] = $showWelcome; |
|
101 | + $variables[ 'settings' ] = Retour::$settings; |
|
102 | 102 | |
103 | 103 | // Render the template |
104 | 104 | return $this->renderTemplate('retour/dashboard/index', $variables); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | Craft::t( |
117 | 117 | 'retour', |
118 | 118 | 'Retour statistics cleared: {error}', |
119 | - ['error' => $error] |
|
119 | + [ 'error' => $error ] |
|
120 | 120 | ), |
121 | 121 | __METHOD__ |
122 | 122 | ); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | Craft::t( |
129 | 129 | 'retour', |
130 | 130 | '404 full URL: {fullUrl}, 404 path only: {pathOnly}', |
131 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
131 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
132 | 132 | ), |
133 | 133 | __METHOD__ |
134 | 134 | ); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $response = Craft::$app->getResponse(); |
163 | 163 | if ($redirect !== null) { |
164 | 164 | // Figure out what type of source matching was done |
165 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
165 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
166 | 166 | switch ($redirectSrcMatch) { |
167 | 167 | case 'pathonly': |
168 | 168 | $url = $pathOnly; |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | $url = $pathOnly; |
175 | 175 | break; |
176 | 176 | } |
177 | - $dest = $redirect['redirectDestUrl']; |
|
177 | + $dest = $redirect[ 'redirectDestUrl' ]; |
|
178 | 178 | // If this isn't a full URL, make it one based on the appropriate site |
179 | 179 | if (!UrlHelper::isFullUrl($dest)) { |
180 | 180 | try { |
181 | - $dest = UrlHelper::siteUrl($dest, null, null, $redirect['siteId'] ?? null); |
|
181 | + $dest = UrlHelper::siteUrl($dest, null, null, $redirect[ 'siteId' ] ?? null); |
|
182 | 182 | } catch (\yii\base\Exception $e) { |
183 | 183 | } |
184 | 184 | } |
@@ -188,12 +188,12 @@ discard block |
||
188 | 188 | $dest .= '?' . $request->getQueryStringWithoutPath(); |
189 | 189 | } |
190 | 190 | } |
191 | - $status = $redirect['redirectHttpCode']; |
|
191 | + $status = $redirect[ 'redirectHttpCode' ]; |
|
192 | 192 | Craft::info( |
193 | 193 | Craft::t( |
194 | 194 | 'retour', |
195 | 195 | 'Redirecting {url} to {dest} with status {status}', |
196 | - ['url' => $url, 'dest' => $dest, 'status' => $status] |
|
196 | + [ 'url' => $url, 'dest' => $dest, 'status' => $status ] |
|
197 | 197 | ), |
198 | 198 | __METHOD__ |
199 | 199 | ); |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | public function getRedirectFromCache($url, int $siteId = 0) |
274 | 274 | { |
275 | 275 | $cache = Craft::$app->getCache(); |
276 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
276 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
277 | 277 | $redirect = $cache->get($cacheKey); |
278 | 278 | Craft::info( |
279 | 279 | Craft::t( |
280 | 280 | 'retour', |
281 | 281 | 'Cached redirect hit for {url}', |
282 | - ['url' => $url] |
|
282 | + [ 'url' => $url ] |
|
283 | 283 | ), |
284 | 284 | __METHOD__ |
285 | 285 | ); |
@@ -301,12 +301,12 @@ discard block |
||
301 | 301 | } catch (SiteNotFoundException $e) { |
302 | 302 | $siteId = 1; |
303 | 303 | } |
304 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
304 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
305 | 305 | // Create the dependency tags |
306 | 306 | $dependency = new TagDependency([ |
307 | 307 | 'tags' => [ |
308 | 308 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
309 | - $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
309 | + $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
310 | 310 | ], |
311 | 311 | ]); |
312 | 312 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | Craft::t( |
315 | 315 | 'retour', |
316 | 316 | 'Cached redirect saved for {url}', |
317 | - ['url' => $url] |
|
317 | + [ 'url' => $url ] |
|
318 | 318 | ), |
319 | 319 | __METHOD__ |
320 | 320 | ); |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | $result = null; |
333 | 333 | foreach ($redirects as $redirect) { |
334 | 334 | // Figure out what type of source matching to do |
335 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
336 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
335 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
336 | + $redirectEnabled = (bool) $redirect[ 'enabled' ]; |
|
337 | 337 | if ($redirectEnabled === true) { |
338 | 338 | switch ($redirectSrcMatch) { |
339 | 339 | case 'pathonly': |
@@ -346,11 +346,11 @@ discard block |
||
346 | 346 | $url = $pathOnly; |
347 | 347 | break; |
348 | 348 | } |
349 | - $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
|
349 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound'; |
|
350 | 350 | switch ($redirectMatchType) { |
351 | 351 | // Do a straight up match |
352 | 352 | case 'exactmatch': |
353 | - if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { |
|
353 | + if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) { |
|
354 | 354 | $this->incrementRedirectHitCount($redirect); |
355 | 355 | $this->saveRedirectToCache($url, $redirect); |
356 | 356 | |
@@ -360,14 +360,14 @@ discard block |
||
360 | 360 | |
361 | 361 | // Do a regex match |
362 | 362 | case 'regexmatch': |
363 | - $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
363 | + $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i'; |
|
364 | 364 | if (preg_match($matchRegEx, $url) === 1) { |
365 | 365 | $this->incrementRedirectHitCount($redirect); |
366 | 366 | // If we're not associated with an EntryID, handle capture group replacement |
367 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
368 | - $redirect['redirectDestUrl'] = preg_replace( |
|
367 | + if ((int) $redirect[ 'associatedElementId' ] === 0) { |
|
368 | + $redirect[ 'redirectDestUrl' ] = preg_replace( |
|
369 | 369 | $matchRegEx, |
370 | - $redirect['redirectDestUrl'], |
|
370 | + $redirect[ 'redirectDestUrl' ], |
|
371 | 371 | $url |
372 | 372 | ); |
373 | 373 | } |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | 'redirect' => &$redirect, |
387 | 387 | ], |
388 | 388 | ]; |
389 | - $result = \call_user_func_array([$plugin, 'retourMatch'], $args); |
|
389 | + $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args); |
|
390 | 390 | if ($result) { |
391 | 391 | $this->incrementRedirectHitCount($redirect); |
392 | 392 | $this->saveRedirectToCache($url, $redirect); |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | Craft::t( |
403 | 403 | 'retour', |
404 | 404 | 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}', |
405 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
405 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
406 | 406 | ), |
407 | 407 | __METHOD__ |
408 | 408 | ); |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
427 | 427 | /** @var Plugin $plugin */ |
428 | 428 | if (method_exists($plugin, 'retourMatch')) { |
429 | - $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
429 | + $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match'); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
@@ -447,12 +447,12 @@ discard block |
||
447 | 447 | } |
448 | 448 | // Query the db table |
449 | 449 | $query = (new Query()) |
450 | - ->from(['{{%retour_static_redirects}}']) |
|
450 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
451 | 451 | ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC'); |
452 | 452 | if ($siteId) { |
453 | 453 | $query |
454 | - ->where(['siteId' => $siteId]) |
|
455 | - ->orWhere(['siteId' => null]); |
|
454 | + ->where([ 'siteId' => $siteId ]) |
|
455 | + ->orWhere([ 'siteId' => null ]); |
|
456 | 456 | } |
457 | 457 | if ($limit) { |
458 | 458 | $query->limit($limit); |
@@ -475,8 +475,8 @@ discard block |
||
475 | 475 | { |
476 | 476 | // Query the db table |
477 | 477 | $redirect = (new Query()) |
478 | - ->from(['{{%retour_static_redirects}}']) |
|
479 | - ->where(['id' => $id]) |
|
478 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
479 | + ->where([ 'id' => $id ]) |
|
480 | 480 | ->one(); |
481 | 481 | |
482 | 482 | return $redirect; |
@@ -494,16 +494,16 @@ discard block |
||
494 | 494 | { |
495 | 495 | // Query the db table |
496 | 496 | $query = (new Query()) |
497 | - ->from(['{{%retour_static_redirects}}']) |
|
498 | - ->where(['redirectSrcUrl' => $redirectSrcUrl]) |
|
497 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
498 | + ->where([ 'redirectSrcUrl' => $redirectSrcUrl ]) |
|
499 | 499 | ; |
500 | 500 | if ($siteId) { |
501 | 501 | $query |
502 | - ->andWhere(['or', [ |
|
502 | + ->andWhere([ 'or', [ |
|
503 | 503 | 'siteId' => $siteId, |
504 | 504 | ], [ |
505 | 505 | 'siteId' => null, |
506 | - ]]); |
|
506 | + ] ]); |
|
507 | 507 | } |
508 | 508 | $redirect = $query->one(); |
509 | 509 | |
@@ -545,13 +545,13 @@ discard block |
||
545 | 545 | { |
546 | 546 | if ($redirectConfig !== null) { |
547 | 547 | $db = Craft::$app->getDb(); |
548 | - $redirectConfig['hitCount']++; |
|
549 | - $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime()); |
|
548 | + $redirectConfig[ 'hitCount' ]++; |
|
549 | + $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime()); |
|
550 | 550 | Craft::debug( |
551 | 551 | Craft::t( |
552 | 552 | 'retour', |
553 | 553 | 'Incrementing statistics for: {redirect}', |
554 | - ['redirect' => print_r($redirectConfig, true)] |
|
554 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
555 | 555 | ), |
556 | 556 | __METHOD__ |
557 | 557 | ); |
@@ -560,14 +560,14 @@ discard block |
||
560 | 560 | $rowsAffected = $db->createCommand()->update( |
561 | 561 | '{{%retour_static_redirects}}', |
562 | 562 | [ |
563 | - 'hitCount' => $redirectConfig['hitCount'], |
|
564 | - 'hitLastTime' => $redirectConfig['hitLastTime'], |
|
563 | + 'hitCount' => $redirectConfig[ 'hitCount' ], |
|
564 | + 'hitLastTime' => $redirectConfig[ 'hitLastTime' ], |
|
565 | 565 | ], |
566 | 566 | [ |
567 | - 'id' => $redirectConfig['id'], |
|
567 | + 'id' => $redirectConfig[ 'id' ], |
|
568 | 568 | ] |
569 | 569 | )->execute(); |
570 | - Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
570 | + Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
571 | 571 | } catch (Exception $e) { |
572 | 572 | Craft::error($e->getMessage(), __METHOD__); |
573 | 573 | } |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | Craft::t( |
587 | 587 | 'retour', |
588 | 588 | 'Error validating redirect {id}: {errors}', |
589 | - ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)] |
|
589 | + [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ] |
|
590 | 590 | ), |
591 | 591 | __METHOD__ |
592 | 592 | ); |
@@ -596,32 +596,32 @@ discard block |
||
596 | 596 | // Get the validated model attributes and save them to the db |
597 | 597 | $redirectConfig = $redirect->getAttributes(); |
598 | 598 | // 0 for a siteId needs to be converted to null |
599 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
600 | - $redirectConfig['siteId'] = null; |
|
599 | + if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) { |
|
600 | + $redirectConfig[ 'siteId' ] = null; |
|
601 | 601 | } |
602 | 602 | // Throw an event to before saving the redirect |
603 | 603 | $db = Craft::$app->getDb(); |
604 | 604 | // See if a redirect exists with this source URL already |
605 | - if ((int)$redirectConfig['id'] === 0) { |
|
605 | + if ((int) $redirectConfig[ 'id' ] === 0) { |
|
606 | 606 | // Query the db table |
607 | 607 | $redirect = (new Query()) |
608 | - ->from(['{{%retour_static_redirects}}']) |
|
609 | - ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']]) |
|
610 | - ->andWhere(['siteId' => $redirectConfig['siteId']]) |
|
608 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
609 | + ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ]) |
|
610 | + ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ]) |
|
611 | 611 | ->one(); |
612 | 612 | // If it exists, update it rather than having duplicates |
613 | 613 | if (!empty($redirect)) { |
614 | - $redirectConfig['id'] = $redirect['id']; |
|
614 | + $redirectConfig[ 'id' ] = $redirect[ 'id' ]; |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | // Trigger a 'beforeSaveRedirect' event |
618 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
618 | + $isNew = (int) $redirectConfig[ 'id' ] === 0; |
|
619 | 619 | $event = new RedirectEvent([ |
620 | 620 | 'isNew' => $isNew, |
621 | - 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
|
622 | - 'destinationUrl' => $redirectConfig['redirectDestUrl'], |
|
623 | - 'matchType' => $redirectConfig['redirectSrcMatch'], |
|
624 | - 'redirectType' => $redirectConfig['redirectHttpCode'], |
|
621 | + 'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ], |
|
622 | + 'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ], |
|
623 | + 'matchType' => $redirectConfig[ 'redirectSrcMatch' ], |
|
624 | + 'redirectType' => $redirectConfig[ 'redirectHttpCode' ], |
|
625 | 625 | ]); |
626 | 626 | $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event); |
627 | 627 | if (!$event->isValid) { |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | Craft::t( |
634 | 634 | 'retour', |
635 | 635 | 'Updating existing redirect: {redirect}', |
636 | - ['redirect' => print_r($redirectConfig, true)] |
|
636 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
637 | 637 | ), |
638 | 638 | __METHOD__ |
639 | 639 | ); |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | '{{%retour_static_redirects}}', |
644 | 644 | $redirectConfig, |
645 | 645 | [ |
646 | - 'id' => $redirectConfig['id'], |
|
646 | + 'id' => $redirectConfig[ 'id' ], |
|
647 | 647 | ] |
648 | 648 | )->execute(); |
649 | 649 | } catch (Exception $e) { |
@@ -654,11 +654,11 @@ discard block |
||
654 | 654 | Craft::t( |
655 | 655 | 'retour', |
656 | 656 | 'Creating new redirect: {redirect}', |
657 | - ['redirect' => print_r($redirectConfig, true)] |
|
657 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
658 | 658 | ), |
659 | 659 | __METHOD__ |
660 | 660 | ); |
661 | - unset($redirectConfig['id']); |
|
661 | + unset($redirectConfig[ 'id' ]); |
|
662 | 662 | // Create a new record |
663 | 663 | try { |
664 | 664 | $db->createCommand()->insert( |
@@ -671,15 +671,15 @@ discard block |
||
671 | 671 | } |
672 | 672 | // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl |
673 | 673 | $testRedirectConfig = $this->getRedirectByRedirectSrcUrl( |
674 | - $redirectConfig['redirectDestUrl'], |
|
675 | - $redirectConfig['siteId'] |
|
674 | + $redirectConfig[ 'redirectDestUrl' ], |
|
675 | + $redirectConfig[ 'siteId' ] |
|
676 | 676 | ); |
677 | 677 | if ($testRedirectConfig !== null) { |
678 | 678 | Craft::debug( |
679 | 679 | Craft::t( |
680 | 680 | 'retour', |
681 | 681 | 'Deleting redirect to prevent a loop: {redirect}', |
682 | - ['redirect' => print_r($testRedirectConfig, true)] |
|
682 | + [ 'redirect' => print_r($testRedirectConfig, true) ] |
|
683 | 683 | ), |
684 | 684 | __METHOD__ |
685 | 685 | ); |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | try { |
688 | 688 | $db->createCommand()->delete( |
689 | 689 | '{{%retour_static_redirects}}', |
690 | - ['id' => $testRedirectConfig['id']] |
|
690 | + [ 'id' => $testRedirectConfig[ 'id' ] ] |
|
691 | 691 | )->execute(); |
692 | 692 | } catch (Exception $e) { |
693 | 693 | Craft::error($e->getMessage(), __METHOD__); |
@@ -720,10 +720,10 @@ discard block |
||
720 | 720 | */ |
721 | 721 | public function excludeUri($uri): bool |
722 | 722 | { |
723 | - $uri = '/'.ltrim($uri, '/'); |
|
723 | + $uri = '/' . ltrim($uri, '/'); |
|
724 | 724 | if (!empty(Retour::$settings->excludePatterns)) { |
725 | 725 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
726 | - $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
726 | + $pattern = '`' . $excludePattern[ 'pattern' ] . '`i'; |
|
727 | 727 | if (preg_match($pattern, $uri) === 1) { |
728 | 728 | return true; |
729 | 729 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | // The number of milliseconds required between trimming of statistics |
52 | 52 | 'statisticsRateLimitMs' => 3600000, |
53 | 53 | |
54 | - // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking |
|
54 | + // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking |
|
55 | 55 | 'excludePatterns' => [ |
56 | 56 | ], |
57 | 57 | ]; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | } |
61 | 61 | // Query the db table |
62 | 62 | $stats = (new Query()) |
63 | - ->from(['{{%retour_stats}}']) |
|
63 | + ->from([ '{{%retour_stats}}' ]) |
|
64 | 64 | ->orderBy('hitCount DESC') |
65 | 65 | ->limit(Retour::$settings->statsDisplayLimit) |
66 | 66 | ->all(); |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | public function getRecentStatistics($days = 1, $handled = false): array |
80 | 80 | { |
81 | 81 | // Ensure is an int |
82 | - $handledInt = (int)$handled; |
|
83 | - $stats = []; |
|
82 | + $handledInt = (int) $handled; |
|
83 | + $stats = [ ]; |
|
84 | 84 | $db = Craft::$app->getDb(); |
85 | 85 | if ($db->getIsMysql()) { |
86 | 86 | // Query the db table |
87 | 87 | $stats = (new Query()) |
88 | - ->from(['{{%retour_stats}}']) |
|
88 | + ->from([ '{{%retour_stats}}' ]) |
|
89 | 89 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )") |
90 | 90 | ->andWhere("handledByRetour = {$handledInt}") |
91 | 91 | ->orderBy('hitLastTime DESC') |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | if ($db->getIsPgsql()) { |
95 | 95 | // Query the db table |
96 | 96 | $stats = (new Query()) |
97 | - ->from(['{{%retour_stats}}']) |
|
97 | + ->from([ '{{%retour_stats}}' ]) |
|
98 | 98 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )") |
99 | - ->andWhere(['handledByRetour' => $handledInt]) |
|
99 | + ->andWhere([ 'handledByRetour' => $handledInt ]) |
|
100 | 100 | ->orderBy('hitLastTime DESC') |
101 | 101 | ->all(); |
102 | 102 | } |
@@ -163,16 +163,16 @@ discard block |
||
163 | 163 | $stats->validate(); |
164 | 164 | // Find any existing retour_stats record |
165 | 165 | $statsConfig = (new Query()) |
166 | - ->from(['{{%retour_stats}}']) |
|
167 | - ->where(['redirectSrcUrl' => $stats->redirectSrcUrl]) |
|
166 | + ->from([ '{{%retour_stats}}' ]) |
|
167 | + ->where([ 'redirectSrcUrl' => $stats->redirectSrcUrl ]) |
|
168 | 168 | ->one(); |
169 | 169 | // If no record is found, initialize some values |
170 | 170 | if ($statsConfig === null) { |
171 | 171 | $stats->id = 0; |
172 | 172 | $stats->hitCount = 0; |
173 | 173 | } else { |
174 | - $stats->id = $statsConfig['id']; |
|
175 | - $stats->hitCount = $statsConfig['hitCount']; |
|
174 | + $stats->id = $statsConfig[ 'id' ]; |
|
175 | + $stats->hitCount = $statsConfig[ 'hitCount' ]; |
|
176 | 176 | } |
177 | 177 | // Merge in the updated info |
178 | 178 | $stats->siteId = $siteId; |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | $stats->userAgent = $userAgent; |
182 | 182 | $stats->exceptionMessage = $exceptionMessage; |
183 | 183 | $stats->exceptionFilePath = $exceptionFilePath; |
184 | - $stats->exceptionFileLine = (int)$exceptionFileLine; |
|
184 | + $stats->exceptionFileLine = (int) $exceptionFileLine; |
|
185 | 185 | $stats->hitLastTime = Db::prepareDateForDb(new \DateTime()); |
186 | - $stats->handledByRetour = (int)$handled; |
|
186 | + $stats->handledByRetour = (int) $handled; |
|
187 | 187 | $stats->hitCount++; |
188 | 188 | $statsConfig = $stats->getAttributes(); |
189 | 189 | // Record the updated statistics |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | Craft::t( |
254 | 254 | 'retour', |
255 | 255 | 'Trimmed {rows} from retour_stats table', |
256 | - ['rows' => $affectedRows] |
|
256 | + [ 'rows' => $affectedRows ] |
|
257 | 257 | ), |
258 | 258 | __METHOD__ |
259 | 259 | ); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | Craft::t( |
275 | 275 | 'retour', |
276 | 276 | 'Error validating statistics {id}: {errors}', |
277 | - ['id' => $stats->id, 'errors' => print_r($stats->getErrors(), true)] |
|
277 | + [ 'id' => $stats->id, 'errors' => print_r($stats->getErrors(), true) ] |
|
278 | 278 | ), |
279 | 279 | __METHOD__ |
280 | 280 | ); |
@@ -284,14 +284,14 @@ discard block |
||
284 | 284 | // Get the validated model attributes and save them to the db |
285 | 285 | $statsConfig = $stats->getAttributes(); |
286 | 286 | $db = Craft::$app->getDb(); |
287 | - if ($statsConfig['id'] !== 0) { |
|
287 | + if ($statsConfig[ 'id' ] !== 0) { |
|
288 | 288 | // Update the existing record |
289 | 289 | try { |
290 | 290 | $result = $db->createCommand()->update( |
291 | 291 | '{{%retour_stats}}', |
292 | 292 | $statsConfig, |
293 | 293 | [ |
294 | - 'id' => $statsConfig['id'], |
|
294 | + 'id' => $statsConfig[ 'id' ], |
|
295 | 295 | ] |
296 | 296 | )->execute(); |
297 | 297 | } catch (Exception $e) { |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | // Craft::error($e->getMessage(), __METHOD__); |
301 | 301 | } |
302 | 302 | } else { |
303 | - unset($statsConfig['id']); |
|
303 | + unset($statsConfig[ 'id' ]); |
|
304 | 304 | // Create a new record |
305 | 305 | try { |
306 | 306 | $db->createCommand()->insert( |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $now = round(microtime(true) * 1000); |
328 | 328 | $cache = Craft::$app->getCache(); |
329 | 329 | $then = $cache->get(self::LAST_STATISTICS_TRIM_CACHE_KEY); |
330 | - if (($then !== false) && ($now - (int)$then < Retour::$settings->statisticsRateLimitMs)) { |
|
330 | + if (($then !== false) && ($now - (int) $then < Retour::$settings->statisticsRateLimitMs)) { |
|
331 | 331 | $limited = true; |
332 | 332 | } |
333 | 333 | $cache->set(self::LAST_STATISTICS_TRIM_CACHE_KEY, $now, 0); |