@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @inheritdoc |
37 | 37 | */ |
38 | - protected array|bool|int $allowAnonymous = [ |
|
38 | + protected array | bool | int $allowAnonymous = [ |
|
39 | 39 | ]; |
40 | 40 | |
41 | 41 | // Public Methods |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | 'COUNT(handledByRetour = 1 or null) as handled_cnt', |
80 | 80 | ]) |
81 | 81 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )"); |
82 | - if ((int)$siteId !== 0) { |
|
82 | + if ((int) $siteId !== 0) { |
|
83 | 83 | $query->andWhere(['siteId' => $siteId]); |
84 | 84 | } |
85 | 85 | $query |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | "COUNT(CASE WHEN \"handledByRetour\" = true THEN 1 END) as handled_cnt", |
98 | 98 | ]) |
99 | 99 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )"); |
100 | - if ((int)$siteId !== 0) { |
|
100 | + if ((int) $siteId !== 0) { |
|
101 | 101 | $query->andWhere(['siteId' => $siteId]); |
102 | 102 | } |
103 | 103 | $query |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | } |
162 | 162 | if ($stats) { |
163 | 163 | $data = [ |
164 | - (int)$stats, |
|
165 | - (int)$handledStats, |
|
164 | + (int) $stats, |
|
165 | + (int) $handledStats, |
|
166 | 166 | ]; |
167 | 167 | } |
168 | 168 |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | // Protected Properties |
90 | 90 | // ========================================================================= |
91 | 91 | |
92 | - protected array|bool|int $allowAnonymous = []; |
|
92 | + protected array | bool | int $allowAnonymous = []; |
|
93 | 93 | |
94 | 94 | // Public Methods |
95 | 95 | // ========================================================================= |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | $variables['docsUrl'] = self::DOCUMENTATION_URL; |
207 | 207 | $variables['pluginName'] = $pluginName; |
208 | 208 | $variables['title'] = $templateTitle; |
209 | - $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
209 | + $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
210 | 210 | $variables['crumbs'] = [ |
211 | 211 | [ |
212 | 212 | 'label' => $pluginName, |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | ], |
215 | 215 | [ |
216 | 216 | 'label' => 'Redirects', |
217 | - 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
217 | + 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
218 | 218 | ], |
219 | 219 | ]; |
220 | 220 | $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $file = UploadedFile::getInstanceByName('file'); |
225 | 225 | if ($file !== null) { |
226 | 226 | $filename = uniqid($file->name, true); |
227 | - $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename; |
|
227 | + $filePath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$filename; |
|
228 | 228 | $file->saveAs($filePath, false); |
229 | 229 | // Also save the file to the cache as a backup way to access it |
230 | 230 | $fileContents = @file_get_contents($filePath); |
@@ -359,9 +359,9 @@ discard block |
||
359 | 359 | $index++; |
360 | 360 | } |
361 | 361 | $redirectDump = print_r($redirectConfig, true); |
362 | - Craft::debug("-> ROW #$rowIndex contents: " . $redirectDump, __METHOD__); |
|
362 | + Craft::debug("-> ROW #$rowIndex contents: ".$redirectDump, __METHOD__); |
|
363 | 363 | if (!Retour::$plugin->redirects->saveRedirect($redirectConfig)) { |
364 | - Craft::info("-> ROW #$rowIndex contents: " . $redirectDump, __METHOD__); |
|
364 | + Craft::info("-> ROW #$rowIndex contents: ".$redirectDump, __METHOD__); |
|
365 | 365 | $hasErrors = true; |
366 | 366 | } |
367 | 367 | $rowIndex++; |
@@ -401,9 +401,9 @@ discard block |
||
401 | 401 | $index++; |
402 | 402 | } |
403 | 403 | $redirectDump = print_r($redirectConfig, true); |
404 | - Craft::debug("-> ROW #$rowIndex contents: " . $redirectDump, __METHOD__); |
|
404 | + Craft::debug("-> ROW #$rowIndex contents: ".$redirectDump, __METHOD__); |
|
405 | 405 | if (!Retour::$plugin->redirects->saveRedirect($redirectConfig)) { |
406 | - Craft::info("-> ROW #$rowIndex contents: " . $redirectDump, __METHOD__); |
|
406 | + Craft::info("-> ROW #$rowIndex contents: ".$redirectDump, __METHOD__); |
|
407 | 407 | $hasErrors = true; |
408 | 408 | } |
409 | 409 | $rowIndex++; |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | } |
440 | 440 | $csv->insertOne(array_values($columns)); |
441 | 441 | $csv->insertAll($data); |
442 | - $csv->output($filename . '.csv'); |
|
442 | + $csv->output($filename.'.csv'); |
|
443 | 443 | exit(0); |
444 | 444 | } |
445 | 445 | } |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | $addSlash = str_ends_with($path, '/'); |
66 | 66 | if (!empty($sitePath)) { |
67 | 67 | // Normalizes a URI path by trimming leading/ trailing slashes and removing double slashes |
68 | - $sitePath = '/' . preg_replace('/\/\/+/', '/', trim($sitePath, '/')); |
|
68 | + $sitePath = '/'.preg_replace('/\/\/+/', '/', trim($sitePath, '/')); |
|
69 | 69 | } |
70 | 70 | // Strip the $sitePath from the incoming $path |
71 | 71 | if (str_starts_with($path, $sitePath)) { |
72 | 72 | $path = substr($path, strlen($sitePath)); |
73 | - $path = '/' . preg_replace('/\/\/+/', '/', trim($path, '/')); |
|
73 | + $path = '/'.preg_replace('/\/\/+/', '/', trim($path, '/')); |
|
74 | 74 | } |
75 | - $path = $addSlash ? $path . '/' : $path; |
|
75 | + $path = $addSlash ? $path.'/' : $path; |
|
76 | 76 | |
77 | 77 | return $path; |
78 | 78 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $sitePath = parse_url($site->baseUrl, PHP_URL_PATH); |
91 | 91 | if (!empty($sitePath)) { |
92 | 92 | // Normalizes a URI path by trimming leading/ trailing slashes and removing double slashes |
93 | - $sitePath = '/' . preg_replace('/\/\/+/', '/', trim($sitePath, '/')); |
|
93 | + $sitePath = '/'.preg_replace('/\/\/+/', '/', trim($sitePath, '/')); |
|
94 | 94 | } |
95 | 95 | // See if the path begins with a site path prefix |
96 | 96 | if ($sitePath !== '/' && str_starts_with($path, $sitePath)) { |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | $overlap = 0; |
114 | 114 | $url = $url ?? ''; |
115 | 115 | $path = $path ?? ''; |
116 | - $url = rtrim($url, '/') . '/'; |
|
117 | - $path = '/' . ltrim($path, '/'); |
|
116 | + $url = rtrim($url, '/').'/'; |
|
117 | + $path = '/'.ltrim($path, '/'); |
|
118 | 118 | $urlOffset = strlen($url); |
119 | 119 | $pathLength = strlen($path); |
120 | 120 | $pathOffset = 0; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
129 | - return rtrim($url, '/') . '/' . ltrim(substr($path, $overlap), '/'); |
|
129 | + return rtrim($url, '/').'/'.ltrim(substr($path, $overlap), '/'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | /** @noinspection CallableParameterUseCaseInTypeContextInspection */ |
147 | 147 | $url = preg_replace('/{.*}/', '', $url); |
148 | 148 | // Remove any linebreaks that may be errantly in the URL |
149 | - $url = (string)str_replace([ |
|
149 | + $url = (string) str_replace([ |
|
150 | 150 | PHP_EOL, |
151 | 151 | "\r", |
152 | 152 | "\n", |
@@ -279,13 +279,13 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function excludeUri($uri): bool |
281 | 281 | { |
282 | - $uri = '/' . ltrim($uri, '/'); |
|
282 | + $uri = '/'.ltrim($uri, '/'); |
|
283 | 283 | if (!empty(Retour::$settings->excludePatterns)) { |
284 | 284 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
285 | 285 | if (empty($excludePattern['pattern'])) { |
286 | 286 | continue; |
287 | 287 | } |
288 | - $pattern = '`' . $excludePattern['pattern'] . '`i'; |
|
288 | + $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
289 | 289 | try { |
290 | 290 | if (preg_match($pattern, $uri) === 1) { |
291 | 291 | Craft::info( |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | } |
302 | 302 | } catch (\Exception $e) { |
303 | 303 | // That's fine |
304 | - Craft::error('Invalid exclude URI Regex: ' . $pattern, __METHOD__); |
|
304 | + Craft::error('Invalid exclude URI Regex: '.$pattern, __METHOD__); |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @return bool|array|null |
318 | 318 | */ |
319 | - public function findRedirectMatch(string $fullUrl, string $pathOnly, $siteId = null): bool|array|null |
|
319 | + public function findRedirectMatch(string $fullUrl, string $pathOnly, $siteId = null): bool | array | null |
|
320 | 320 | { |
321 | 321 | // Get the current site |
322 | 322 | if ($siteId === null) { |
@@ -369,10 +369,10 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @return bool|array |
371 | 371 | */ |
372 | - public function getRedirectFromCache(string $url, int $siteId = 0): bool|array |
|
372 | + public function getRedirectFromCache(string $url, int $siteId = 0): bool | array |
|
373 | 373 | { |
374 | 374 | $cache = Craft::$app->getCache(); |
375 | - $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
375 | + $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
376 | 376 | $redirect = $cache->get($cacheKey); |
377 | 377 | Craft::info( |
378 | 378 | Craft::t( |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | 'id' => $redirectConfig['id'], |
418 | 418 | ] |
419 | 419 | )->execute(); |
420 | - Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
420 | + Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
421 | 421 | } catch (\Exception $e) { |
422 | 422 | Craft::error($e->getMessage(), __METHOD__); |
423 | 423 | } |
@@ -438,12 +438,12 @@ discard block |
||
438 | 438 | } catch (SiteNotFoundException $e) { |
439 | 439 | $siteId = 1; |
440 | 440 | } |
441 | - $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
441 | + $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
442 | 442 | // Create the dependency tags |
443 | 443 | $dependency = new TagDependency([ |
444 | 444 | 'tags' => [ |
445 | 445 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
446 | - $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
446 | + $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
447 | 447 | ], |
448 | 448 | ]); |
449 | 449 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | foreach ($redirects as $redirect) { |
638 | 638 | // Figure out what type of source matching to do |
639 | 639 | $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
640 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
640 | + $redirectEnabled = (bool) $redirect['enabled']; |
|
641 | 641 | if ($redirectEnabled === true) { |
642 | 642 | switch ($redirectSrcMatch) { |
643 | 643 | case 'pathonly': |
@@ -678,12 +678,12 @@ discard block |
||
678 | 678 | |
679 | 679 | // Do a regex match |
680 | 680 | case 'regexmatch': |
681 | - $matchRegEx = '`' . $redirect['redirectSrcUrlParsed'] . '`i'; |
|
681 | + $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
682 | 682 | try { |
683 | 683 | if (preg_match($matchRegEx, $url) === 1) { |
684 | 684 | $this->incrementRedirectHitCount($redirect); |
685 | 685 | // If we're not associated with an EntryID, handle capture group replacement |
686 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
686 | + if ((int) $redirect['associatedElementId'] === 0) { |
|
687 | 687 | $redirect['redirectDestUrl'] = preg_replace( |
688 | 688 | $matchRegEx, |
689 | 689 | $redirect['redirectDestUrl'], |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | } |
712 | 712 | } catch (\Exception $e) { |
713 | 713 | // That's fine |
714 | - Craft::error('Invalid Redirect Regex: ' . $matchRegEx, __METHOD__); |
|
714 | + Craft::error('Invalid Redirect Regex: '.$matchRegEx, __METHOD__); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | break; |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | try { |
828 | 828 | $siteId = $redirect['siteId'] ?? null; |
829 | 829 | if ($siteId !== null) { |
830 | - $siteId = (int)$siteId; |
|
830 | + $siteId = (int) $siteId; |
|
831 | 831 | } |
832 | 832 | if (!UrlHelper::isAbsoluteUrl($dest) && !UrlHelper::pathHasSitePrefix($path)) { |
833 | 833 | $dest = UrlHelper::siteUrl('/', null, null, $siteId); |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | try { |
850 | 850 | $siteId = $redirect['siteId'] ?? null; |
851 | 851 | if ($siteId !== null) { |
852 | - $siteId = (int)$siteId; |
|
852 | + $siteId = (int) $siteId; |
|
853 | 853 | } |
854 | 854 | $dest = UrlHelper::siteUrl($dest, null, null, $siteId); |
855 | 855 | } catch (\yii\base\Exception $e) { |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | // That's ok |
865 | 865 | } |
866 | 866 | if (!empty($queryString)) { |
867 | - $dest = strtok($dest, '?') . '?' . $queryString; |
|
867 | + $dest = strtok($dest, '?').'?'.$queryString; |
|
868 | 868 | } |
869 | 869 | } |
870 | 870 | $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
939 | 939 | /** @var Plugin $plugin */ |
940 | 940 | if (method_exists($plugin, 'retourMatch')) { |
941 | - $result[$plugin->getHandle()] = $plugin->name . Craft::t('retour', ' Match'); |
|
941 | + $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
942 | 942 | } |
943 | 943 | } |
944 | 944 | |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | $db = Craft::$app->getDb(); |
976 | 976 | // Trigger a 'beforeDeleteRedirect' event |
977 | 977 | $redirectConfig = $this->getRedirectById($id); |
978 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
978 | + $isNew = (int) $redirectConfig['id'] === 0; |
|
979 | 979 | $event = new RedirectEvent([ |
980 | 980 | 'isNew' => $isNew, |
981 | 981 | 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
@@ -1139,7 +1139,7 @@ discard block |
||
1139 | 1139 | // Get the validated model attributes and save them to the db |
1140 | 1140 | $redirectConfig = $redirect->getAttributes(); |
1141 | 1141 | // 0 for a siteId needs to be converted to null |
1142 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
1142 | + if (empty($redirectConfig['siteId']) || (int) $redirectConfig['siteId'] === 0) { |
|
1143 | 1143 | $redirectConfig['siteId'] = null; |
1144 | 1144 | } |
1145 | 1145 | // Throw an event to before saving the redirect |
@@ -1149,7 +1149,7 @@ discard block |
||
1149 | 1149 | } |
1150 | 1150 | |
1151 | 1151 | // See if a redirect exists with this source URL already |
1152 | - if ((int)$redirectConfig['id'] === 0) { |
|
1152 | + if ((int) $redirectConfig['id'] === 0) { |
|
1153 | 1153 | // Query the db table |
1154 | 1154 | $redirect = (new Query()) |
1155 | 1155 | ->from(['{{%retour_static_redirects}}']) |
@@ -1162,7 +1162,7 @@ discard block |
||
1162 | 1162 | } |
1163 | 1163 | } |
1164 | 1164 | // Trigger a 'beforeSaveRedirect' event |
1165 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
1165 | + $isNew = (int) $redirectConfig['id'] === 0; |
|
1166 | 1166 | $event = new RedirectEvent([ |
1167 | 1167 | 'isNew' => $isNew, |
1168 | 1168 | 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |