@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | { |
| 37 | 37 | foreach ($config as $propName => $propValue) { |
| 38 | 38 | if (!property_exists($class, $propName)) { |
| 39 | - unset($config[$propName]); |
|
| 39 | + unset($config[ $propName ]); |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @inheritdoc |
| 49 | 49 | */ |
| 50 | - public function __construct(array $config = []) |
|
| 50 | + public function __construct(array $config = [ ]) |
|
| 51 | 51 | { |
| 52 | 52 | // Unset any deprecated properties |
| 53 | 53 | self::cleanProperties(static::class, $config); |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | public function rules() |
| 76 | 76 | { |
| 77 | 77 | return [ |
| 78 | - ['pluginName', 'string'], |
|
| 79 | - ['pluginName', 'default', 'value' => 'Retour'], |
|
| 78 | + [ 'pluginName', 'string' ], |
|
| 79 | + [ 'pluginName', 'default', 'value' => 'Retour' ], |
|
| 80 | 80 | [ |
| 81 | 81 | [ |
| 82 | 82 | 'createUriChangeRedirects', |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | ], |
| 86 | 86 | 'boolean' |
| 87 | 87 | ], |
| 88 | - ['staticRedirectDisplayLimit', 'integer', 'min' => 1], |
|
| 89 | - ['staticRedirectDisplayLimit', 'default', 'value' => 100], |
|
| 90 | - ['dynamicRedirectDisplayLimit', 'integer', 'min' => 1], |
|
| 91 | - ['dynamicRedirectDisplayLimit', 'default', 'value' => 100], |
|
| 92 | - ['statsStoredLimit', 'integer', 'min' => 1], |
|
| 93 | - ['statsStoredLimit', 'default', 'value' => 1000], |
|
| 94 | - ['statsDisplayLimit', 'integer', 'min' => 1], |
|
| 95 | - ['statsDisplayLimit', 'default', 'value' => 1000], |
|
| 88 | + [ 'staticRedirectDisplayLimit', 'integer', 'min' => 1 ], |
|
| 89 | + [ 'staticRedirectDisplayLimit', 'default', 'value' => 100 ], |
|
| 90 | + [ 'dynamicRedirectDisplayLimit', 'integer', 'min' => 1 ], |
|
| 91 | + [ 'dynamicRedirectDisplayLimit', 'default', 'value' => 100 ], |
|
| 92 | + [ 'statsStoredLimit', 'integer', 'min' => 1 ], |
|
| 93 | + [ 'statsStoredLimit', 'default', 'value' => 1000 ], |
|
| 94 | + [ 'statsDisplayLimit', 'integer', 'min' => 1 ], |
|
| 95 | + [ 'statsDisplayLimit', 'default', 'value' => 1000 ], |
|
| 96 | 96 | ]; |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -62,18 +62,18 @@ |
||
| 62 | 62 | public function rules() |
| 63 | 63 | { |
| 64 | 64 | return [ |
| 65 | - ['id', 'integer'], |
|
| 66 | - ['redirectSrcUrl', DbStringValidator::class, 'max' => 255], |
|
| 67 | - ['redirectSrcUrl', 'string'], |
|
| 68 | - ['redirectSrcUrl', 'default', 'value' => ''], |
|
| 69 | - ['referrerUrl', DbStringValidator::class, 'max' => 2000], |
|
| 70 | - ['referrerUrl', 'string'], |
|
| 71 | - ['referrerUrl', 'default', 'value' => ''], |
|
| 72 | - ['hitCount', 'integer'], |
|
| 73 | - ['hitCount', 'default', 'value' => 0], |
|
| 74 | - ['hitLastTime', 'safe'], |
|
| 75 | - ['handledByRetour', 'integer', 'min' => 0, 'max' => 1], |
|
| 76 | - ['handledByRetour', 'default', 'value' => 0], |
|
| 65 | + [ 'id', 'integer' ], |
|
| 66 | + [ 'redirectSrcUrl', DbStringValidator::class, 'max' => 255 ], |
|
| 67 | + [ 'redirectSrcUrl', 'string' ], |
|
| 68 | + [ 'redirectSrcUrl', 'default', 'value' => '' ], |
|
| 69 | + [ 'referrerUrl', DbStringValidator::class, 'max' => 2000 ], |
|
| 70 | + [ 'referrerUrl', 'string' ], |
|
| 71 | + [ 'referrerUrl', 'default', 'value' => '' ], |
|
| 72 | + [ 'hitCount', 'integer' ], |
|
| 73 | + [ 'hitCount', 'default', 'value' => 0 ], |
|
| 74 | + [ 'hitLastTime', 'safe' ], |
|
| 75 | + [ 'handledByRetour', 'integer', 'min' => 0, 'max' => 1 ], |
|
| 76 | + [ 'handledByRetour', 'default', 'value' => 0 ], |
|
| 77 | 77 | ]; |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | if (!empty($string)) { |
| 45 | 45 | $string = strip_tags($string); |
| 46 | - $result = (string)Stringy::create($string)->truncate($length, $substring); |
|
| 46 | + $result = (string) Stringy::create($string)->truncate($length, $substring); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | return $result; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | if (!empty($string)) { |
| 69 | 69 | $string = strip_tags($string); |
| 70 | - $result = (string)Stringy::create($string)->safeTruncate($length, $substring); |
|
| 70 | + $result = (string) Stringy::create($string)->safeTruncate($length, $substring); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | return $result; |
@@ -42,43 +42,43 @@ discard block |
||
| 42 | 42 | $sites = Craft::$app->getSites(); |
| 43 | 43 | if (Craft::$app->getIsMultiSite()) { |
| 44 | 44 | // Set defaults based on the section settings |
| 45 | - $variables['enabledSiteIds'] = []; |
|
| 46 | - $variables['siteIds'] = []; |
|
| 45 | + $variables[ 'enabledSiteIds' ] = [ ]; |
|
| 46 | + $variables[ 'siteIds' ] = [ ]; |
|
| 47 | 47 | |
| 48 | 48 | /** @var Site $site */ |
| 49 | 49 | foreach ($sites->getEditableSiteIds() as $editableSiteId) { |
| 50 | - $variables['enabledSiteIds'][] = $editableSiteId; |
|
| 51 | - $variables['siteIds'][] = $editableSiteId; |
|
| 50 | + $variables[ 'enabledSiteIds' ][ ] = $editableSiteId; |
|
| 51 | + $variables[ 'siteIds' ][ ] = $editableSiteId; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // Make sure the $siteId they are trying to edit is in our array of editable sites |
| 55 | - if (!\in_array($siteId, $variables['enabledSiteIds'], false)) { |
|
| 56 | - if (!empty($variables['enabledSiteIds'])) { |
|
| 57 | - $siteId = reset($variables['enabledSiteIds']); |
|
| 55 | + if (!\in_array($siteId, $variables[ 'enabledSiteIds' ], false)) { |
|
| 56 | + if (!empty($variables[ 'enabledSiteIds' ])) { |
|
| 57 | + $siteId = reset($variables[ 'enabledSiteIds' ]); |
|
| 58 | 58 | } else { |
| 59 | - self::requirePermission('editSite:'.$siteId); |
|
| 59 | + self::requirePermission('editSite:' . $siteId); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | // Set the currentSiteId and currentSiteHandle |
| 64 | - $variables['currentSiteId'] = empty($siteId) ? Craft::$app->getSites()->currentSite->id : $siteId; |
|
| 65 | - $variables['currentSiteHandle'] = empty($siteHandle) |
|
| 64 | + $variables[ 'currentSiteId' ] = empty($siteId) ? Craft::$app->getSites()->currentSite->id : $siteId; |
|
| 65 | + $variables[ 'currentSiteHandle' ] = empty($siteHandle) |
|
| 66 | 66 | ? Craft::$app->getSites()->currentSite->handle |
| 67 | 67 | : $siteHandle; |
| 68 | 68 | |
| 69 | 69 | // Page title |
| 70 | - $variables['showSites'] = ( |
|
| 70 | + $variables[ 'showSites' ] = ( |
|
| 71 | 71 | Craft::$app->getIsMultiSite() && |
| 72 | - \count($variables['enabledSiteIds']) |
|
| 72 | + \count($variables[ 'enabledSiteIds' ]) |
|
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | - if ($variables['showSites']) { |
|
| 76 | - $variables['sitesMenuLabel'] = Craft::t( |
|
| 75 | + if ($variables[ 'showSites' ]) { |
|
| 76 | + $variables[ 'sitesMenuLabel' ] = Craft::t( |
|
| 77 | 77 | 'site', |
| 78 | - $sites->getSiteById((int)$variables['currentSiteId'])->name |
|
| 78 | + $sites->getSiteById((int) $variables[ 'currentSiteId' ])->name |
|
| 79 | 79 | ); |
| 80 | 80 | } else { |
| 81 | - $variables['sitesMenuLabel'] = ''; |
|
| 81 | + $variables[ 'sitesMenuLabel' ] = ''; |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | if ($siteHandle !== null) { |
| 97 | 97 | $site = Craft::$app->getSites()->getSiteByHandle($siteHandle); |
| 98 | 98 | if (!$site) { |
| 99 | - throw new NotFoundHttpException('Invalid site handle: '.$siteHandle); |
|
| 99 | + throw new NotFoundHttpException('Invalid site handle: ' . $siteHandle); |
|
| 100 | 100 | } |
| 101 | 101 | $siteId = $site->id; |
| 102 | 102 | } else { |
@@ -78,8 +78,8 @@ |
||
| 78 | 78 | $rules = array_merge( |
| 79 | 79 | $rules, |
| 80 | 80 | [ |
| 81 | - ['numberOfDays', 'integer', 'min' => 1], |
|
| 82 | - ['numberOfDays', 'default', 'value' => 30], |
|
| 81 | + [ 'numberOfDays', 'integer', 'min' => 1 ], |
|
| 82 | + [ 'numberOfDays', 'default', 'value' => 30 ], |
|
| 83 | 83 | ] |
| 84 | 84 | ); |
| 85 | 85 | return $rules; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | // Protected Properties |
| 40 | 40 | // ========================================================================= |
| 41 | 41 | |
| 42 | - protected $allowAnonymous = []; |
|
| 42 | + protected $allowAnonymous = [ ]; |
|
| 43 | 43 | |
| 44 | 44 | // Public Methods |
| 45 | 45 | // ========================================================================= |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function actionPluginSettings($settings = null): Response |
| 56 | 56 | { |
| 57 | - $variables = []; |
|
| 57 | + $variables = [ ]; |
|
| 58 | 58 | PermissionHelper::controllerPermissionCheck('retour:settings'); |
| 59 | 59 | if ($settings === null) { |
| 60 | 60 | $settings = Retour::$settings; |
@@ -69,16 +69,16 @@ discard block |
||
| 69 | 69 | } catch (InvalidConfigException $e) { |
| 70 | 70 | Craft::error($e->getMessage(), __METHOD__); |
| 71 | 71 | } |
| 72 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
| 72 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
| 73 | 73 | '@nystudio107/retour/assetbundles/retour/dist', |
| 74 | 74 | true |
| 75 | 75 | ); |
| 76 | 76 | // Basic variables |
| 77 | - $variables['fullPageForm'] = true; |
|
| 78 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
| 79 | - $variables['pluginName'] = $pluginName; |
|
| 80 | - $variables['title'] = $templateTitle; |
|
| 81 | - $variables['crumbs'] = [ |
|
| 77 | + $variables[ 'fullPageForm' ] = true; |
|
| 78 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
| 79 | + $variables[ 'pluginName' ] = $pluginName; |
|
| 80 | + $variables[ 'title' ] = $templateTitle; |
|
| 81 | + $variables[ 'crumbs' ] = [ |
|
| 82 | 82 | [ |
| 83 | 83 | 'label' => $pluginName, |
| 84 | 84 | 'url' => UrlHelper::cpUrl('retour'), |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | 'url' => UrlHelper::cpUrl('retour/settings'), |
| 89 | 89 | ], |
| 90 | 90 | ]; |
| 91 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
| 92 | - $variables['selectedSubnavItem'] = 'settings'; |
|
| 93 | - $variables['settings'] = $settings; |
|
| 91 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
| 92 | + $variables[ 'selectedSubnavItem' ] = 'settings'; |
|
| 93 | + $variables[ 'settings' ] = $settings; |
|
| 94 | 94 | |
| 95 | 95 | // Render the template |
| 96 | 96 | return $this->renderTemplate('retour/settings', $variables); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | PermissionHelper::controllerPermissionCheck('retour:settings'); |
| 111 | 111 | $this->requirePostRequest(); |
| 112 | 112 | $pluginHandle = Craft::$app->getRequest()->getRequiredBodyParam('pluginHandle'); |
| 113 | - $settings = Craft::$app->getRequest()->getBodyParam('settings', []); |
|
| 113 | + $settings = Craft::$app->getRequest()->getBodyParam('settings', [ ]); |
|
| 114 | 114 | $plugin = Craft::$app->getPlugins()->getPlugin($pluginHandle); |
| 115 | 115 | |
| 116 | 116 | if ($plugin === null) { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | } |
| 58 | 58 | // Query the db table |
| 59 | 59 | $stats = (new Query()) |
| 60 | - ->from(['{{%retour_stats}}']) |
|
| 60 | + ->from([ '{{%retour_stats}}' ]) |
|
| 61 | 61 | ->orderBy('hitCount DESC') |
| 62 | 62 | ->limit(Retour::$settings->statsDisplayLimit) |
| 63 | 63 | ->all(); |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | public function getRecentStatistics($days = 1, $handled = false): array |
| 77 | 77 | { |
| 78 | 78 | // Ensure is an int |
| 79 | - $handledInt = (int)$handled; |
|
| 79 | + $handledInt = (int) $handled; |
|
| 80 | 80 | // Query the db table |
| 81 | 81 | $stats = (new Query()) |
| 82 | - ->from(['{{%retour_stats}}']) |
|
| 82 | + ->from([ '{{%retour_stats}}' ]) |
|
| 83 | 83 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )") |
| 84 | 84 | ->andWhere("handledByRetour = {$handledInt}") |
| 85 | 85 | ->orderBy('hitLastTime DESC') |
@@ -131,21 +131,21 @@ discard block |
||
| 131 | 131 | $stats->validate(); |
| 132 | 132 | // Find any existing retour_stats record |
| 133 | 133 | $statsConfig = (new Query()) |
| 134 | - ->from(['{{%retour_stats}}']) |
|
| 135 | - ->where(['redirectSrcUrl' => $stats->redirectSrcUrl]) |
|
| 134 | + ->from([ '{{%retour_stats}}' ]) |
|
| 135 | + ->where([ 'redirectSrcUrl' => $stats->redirectSrcUrl ]) |
|
| 136 | 136 | ->one(); |
| 137 | 137 | // If no record is found, initialize some values |
| 138 | 138 | if ($statsConfig === null) { |
| 139 | 139 | $stats->id = 0; |
| 140 | 140 | $stats->hitCount = 0; |
| 141 | 141 | } else { |
| 142 | - $stats->id = $statsConfig['id']; |
|
| 143 | - $stats->hitCount = $statsConfig['hitCount']; |
|
| 142 | + $stats->id = $statsConfig[ 'id' ]; |
|
| 143 | + $stats->hitCount = $statsConfig[ 'hitCount' ]; |
|
| 144 | 144 | } |
| 145 | 145 | // Merge in the updated info |
| 146 | 146 | $stats->referrerUrl = $referrer; |
| 147 | 147 | $stats->hitLastTime = Db::prepareDateForDb(new \DateTime()); |
| 148 | - $stats->handledByRetour = (int)$handled; |
|
| 148 | + $stats->handledByRetour = (int) $handled; |
|
| 149 | 149 | $stats->hitCount++; |
| 150 | 150 | $statsConfig = $stats->getAttributes(); |
| 151 | 151 | // Record the updated statistics |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | Craft::t( |
| 193 | 193 | 'retour', |
| 194 | 194 | 'Trimmed {rows} from retour_stats table', |
| 195 | - ['rows' => $affectedRows] |
|
| 195 | + [ 'rows' => $affectedRows ] |
|
| 196 | 196 | ), |
| 197 | 197 | __METHOD__ |
| 198 | 198 | ); |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | Craft::t( |
| 212 | 212 | 'retour', |
| 213 | 213 | 'Error validating statistics {id}: {errors}', |
| 214 | - ['id' => $stats->id, 'errors' => print_r($stats->getErrors(), true)] |
|
| 214 | + [ 'id' => $stats->id, 'errors' => print_r($stats->getErrors(), true) ] |
|
| 215 | 215 | ), |
| 216 | 216 | __METHOD__ |
| 217 | 217 | ); |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | // Get the validated model attributes and save them to the db |
| 222 | 222 | $statsConfig = $stats->getAttributes(); |
| 223 | 223 | $db = Craft::$app->getDb(); |
| 224 | - if ($statsConfig['id'] !== 0) { |
|
| 224 | + if ($statsConfig[ 'id' ] !== 0) { |
|
| 225 | 225 | // Update the existing record |
| 226 | 226 | try { |
| 227 | 227 | $result = $db->createCommand()->update( |
| 228 | 228 | '{{%retour_stats}}', |
| 229 | 229 | $statsConfig, |
| 230 | 230 | [ |
| 231 | - 'id' => $statsConfig['id'], |
|
| 231 | + 'id' => $statsConfig[ 'id' ], |
|
| 232 | 232 | ] |
| 233 | 233 | )->execute(); |
| 234 | 234 | } catch (Exception $e) { |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | public function actionDashboard(string $range = 'day'): Response |
| 55 | 55 | { |
| 56 | 56 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
| 57 | - $data = []; |
|
| 57 | + $data = [ ]; |
|
| 58 | 58 | $days = 1; |
| 59 | 59 | switch ($range) { |
| 60 | 60 | case 'day': |
@@ -80,12 +80,12 @@ discard block |
||
| 80 | 80 | ->groupBy('DAY(hitLastTime)') |
| 81 | 81 | ->all(); |
| 82 | 82 | if ($stats) { |
| 83 | - $data[] = [ |
|
| 83 | + $data[ ] = [ |
|
| 84 | 84 | 'name' => '404 hits', |
| 85 | 85 | 'data' => ArrayHelper::getColumn($stats, 'cnt'), |
| 86 | 86 | 'labels' => ArrayHelper::getColumn($stats, 'hitLastTime'), |
| 87 | 87 | ]; |
| 88 | - $data[] = [ |
|
| 88 | + $data[ ] = [ |
|
| 89 | 89 | 'name' => 'Handled 404 hits', |
| 90 | 90 | 'data' => ArrayHelper::getColumn($stats, 'handled_cnt'), |
| 91 | 91 | 'labels' => ArrayHelper::getColumn($stats, 'hitLastTime'), |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function actionWidget($days = 1): Response |
| 106 | 106 | { |
| 107 | - $data = []; |
|
| 107 | + $data = [ ]; |
|
| 108 | 108 | // Query the db |
| 109 | 109 | $stats = (new Query()) |
| 110 | 110 | ->from('{{%retour_stats}}') |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | ->count(); |
| 118 | 118 | if ($stats) { |
| 119 | 119 | $data = [ |
| 120 | - (int)$stats, |
|
| 121 | - (int)$handledStats |
|
| 120 | + (int) $stats, |
|
| 121 | + (int) $handledStats |
|
| 122 | 122 | ]; |
| 123 | 123 | } |
| 124 | 124 | |