@@ -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", |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | try { |
281 | 281 | $siteId = $redirect['siteId'] ?? null; |
282 | 282 | if ($siteId !== null) { |
283 | - $siteId = (int)$siteId; |
|
283 | + $siteId = (int) $siteId; |
|
284 | 284 | } |
285 | 285 | if (!UrlHelper::isAbsoluteUrl($dest) && !UrlHelper::pathHasSitePrefix($path)) { |
286 | 286 | $dest = UrlHelper::siteUrl('/', null, null, $siteId); |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | try { |
303 | 303 | $siteId = $redirect['siteId'] ?? null; |
304 | 304 | if ($siteId !== null) { |
305 | - $siteId = (int)$siteId; |
|
305 | + $siteId = (int) $siteId; |
|
306 | 306 | } |
307 | 307 | $dest = UrlHelper::siteUrl($dest, null, null, $siteId); |
308 | 308 | } catch (\yii\base\Exception $e) { |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | // That's ok |
318 | 318 | } |
319 | 319 | if (!empty($queryString)) { |
320 | - $dest = strtok($dest, '?') . '?' . $queryString; |
|
320 | + $dest = strtok($dest, '?').'?'.$queryString; |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | public function getRedirectFromCache($url, ?int $siteId = 0) |
439 | 439 | { |
440 | 440 | $cache = Craft::$app->getCache(); |
441 | - $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
441 | + $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
442 | 442 | $redirect = $cache->get($cacheKey); |
443 | 443 | Craft::info( |
444 | 444 | Craft::t( |
@@ -466,12 +466,12 @@ discard block |
||
466 | 466 | } catch (SiteNotFoundException $e) { |
467 | 467 | $siteId = 1; |
468 | 468 | } |
469 | - $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
469 | + $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
470 | 470 | // Create the dependency tags |
471 | 471 | $dependency = new TagDependency([ |
472 | 472 | 'tags' => [ |
473 | 473 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
474 | - $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
474 | + $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
475 | 475 | ], |
476 | 476 | ]); |
477 | 477 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | foreach ($redirects as $redirect) { |
512 | 512 | // Figure out what type of source matching to do |
513 | 513 | $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
514 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
514 | + $redirectEnabled = (bool) $redirect['enabled']; |
|
515 | 515 | if ($redirectEnabled === true) { |
516 | 516 | switch ($redirectSrcMatch) { |
517 | 517 | case 'pathonly': |
@@ -552,12 +552,12 @@ discard block |
||
552 | 552 | |
553 | 553 | // Do a regex match |
554 | 554 | case 'regexmatch': |
555 | - $matchRegEx = '`' . $redirect['redirectSrcUrlParsed'] . '`i'; |
|
555 | + $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
556 | 556 | try { |
557 | 557 | if (preg_match($matchRegEx, $url) === 1) { |
558 | 558 | $this->incrementRedirectHitCount($redirect); |
559 | 559 | // If we're not associated with an EntryID, handle capture group replacement |
560 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
560 | + if ((int) $redirect['associatedElementId'] === 0) { |
|
561 | 561 | $redirect['redirectDestUrl'] = preg_replace( |
562 | 562 | $matchRegEx, |
563 | 563 | $redirect['redirectDestUrl'], |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | } |
586 | 586 | } catch (\Exception $e) { |
587 | 587 | // That's fine |
588 | - Craft::error('Invalid Redirect Regex: ' . $matchRegEx, __METHOD__); |
|
588 | + Craft::error('Invalid Redirect Regex: '.$matchRegEx, __METHOD__); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | break; |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
694 | 694 | /** @var Plugin $plugin */ |
695 | 695 | if (method_exists($plugin, 'retourMatch')) { |
696 | - $result[$plugin->getHandle()] = $plugin->name . Craft::t('retour', ' Match'); |
|
696 | + $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
697 | 697 | } |
698 | 698 | } |
699 | 699 | |
@@ -934,7 +934,7 @@ discard block |
||
934 | 934 | $db = Craft::$app->getDb(); |
935 | 935 | // Trigger a 'beforeDeleteRedirect' event |
936 | 936 | $redirectConfig = $this->getRedirectById($id); |
937 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
937 | + $isNew = (int) $redirectConfig['id'] === 0; |
|
938 | 938 | $event = new RedirectEvent([ |
939 | 939 | 'isNew' => $isNew, |
940 | 940 | 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | 'id' => $redirectConfig['id'], |
996 | 996 | ] |
997 | 997 | )->execute(); |
998 | - Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
998 | + Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
999 | 999 | } catch (\Exception $e) { |
1000 | 1000 | Craft::error($e->getMessage(), __METHOD__); |
1001 | 1001 | } |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | // Get the validated model attributes and save them to the db |
1112 | 1112 | $redirectConfig = $redirect->getAttributes(); |
1113 | 1113 | // 0 for a siteId needs to be converted to null |
1114 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
1114 | + if (empty($redirectConfig['siteId']) || (int) $redirectConfig['siteId'] === 0) { |
|
1115 | 1115 | $redirectConfig['siteId'] = null; |
1116 | 1116 | } |
1117 | 1117 | // Throw an event to before saving the redirect |
@@ -1121,7 +1121,7 @@ discard block |
||
1121 | 1121 | } |
1122 | 1122 | |
1123 | 1123 | // See if a redirect exists with this source URL already |
1124 | - if ((int)$redirectConfig['id'] === 0) { |
|
1124 | + if ((int) $redirectConfig['id'] === 0) { |
|
1125 | 1125 | // Query the db table |
1126 | 1126 | $redirect = (new Query()) |
1127 | 1127 | ->from(['{{%retour_static_redirects}}']) |
@@ -1134,7 +1134,7 @@ discard block |
||
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | // Trigger a 'beforeSaveRedirect' event |
1137 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
1137 | + $isNew = (int) $redirectConfig['id'] === 0; |
|
1138 | 1138 | $event = new RedirectEvent([ |
1139 | 1139 | 'isNew' => $isNew, |
1140 | 1140 | 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
@@ -1213,13 +1213,13 @@ discard block |
||
1213 | 1213 | */ |
1214 | 1214 | public function excludeUri($uri): bool |
1215 | 1215 | { |
1216 | - $uri = '/' . ltrim($uri, '/'); |
|
1216 | + $uri = '/'.ltrim($uri, '/'); |
|
1217 | 1217 | if (!empty(Retour::$settings->excludePatterns)) { |
1218 | 1218 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
1219 | 1219 | if (empty($excludePattern['pattern'])) { |
1220 | 1220 | continue; |
1221 | 1221 | } |
1222 | - $pattern = '`' . $excludePattern['pattern'] . '`i'; |
|
1222 | + $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
1223 | 1223 | try { |
1224 | 1224 | if (preg_match($pattern, $uri) === 1) { |
1225 | 1225 | Craft::info( |
@@ -1235,7 +1235,7 @@ discard block |
||
1235 | 1235 | } |
1236 | 1236 | } catch (\Exception $e) { |
1237 | 1237 | // That's fine |
1238 | - Craft::error('Invalid exclude URI Regex: ' . $pattern, __METHOD__); |
|
1238 | + Craft::error('Invalid exclude URI Regex: '.$pattern, __METHOD__); |
|
1239 | 1239 | } |
1240 | 1240 | } |
1241 | 1241 | } |