Passed
Push — develop ( d08077...e83cf3 )
by Andrew
05:39
created
src/gql/types/RetourType.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
45 45
     {
46 46
         $fieldName = $resolveInfo->fieldName;
47 47
 
48
-        return $source[$fieldName];
48
+        return $source[ $fieldName ];
49 49
     }
50 50
 }
Please login to merge, or discard this patch.
src/gql/resolvers/RetourResolver.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,8 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/gql/interfaces/RetourInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,9 +48,9 @@
 block discarded – undo
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
         ]));
Please login to merge, or discard this patch.
src/gql/types/generators/RetourGenerator.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -34,24 +34,24 @@
 block discarded – undo
34 34
      */
35 35
     public static function generateTypes($context = null): array
36 36
     {
37
-        $gqlTypes = [];
37
+        $gqlTypes = [ ];
38 38
         $retourFields = RetourInterface::getFieldDefinitions();
39 39
         $retourArgs = RetourArguments::getArguments();
40 40
         $typeName = self::getName();
41 41
         $retourType = GqlEntityRegistry::getEntity($typeName)
42 42
             ?: GqlEntityRegistry::createEntity($typeName, new RetourType([
43 43
                 'name' => $typeName,
44
-                'args' => function () use ($retourArgs) {
44
+                'args' => function() use ($retourArgs) {
45 45
                     return $retourArgs;
46 46
                 },
47
-                'fields' => function () use ($retourFields) {
47
+                'fields' => function() use ($retourFields) {
48 48
                     return $retourFields;
49 49
                 },
50 50
                 'description' => 'This entity has all the Retour fields',
51 51
             ]));
52 52
 
53
-        $gqlTypes[$typeName] = $retourType;
54
-        TypeLoader::registerType($typeName, function () use ($retourType) {
53
+        $gqlTypes[ $typeName ] = $retourType;
54
+        TypeLoader::registerType($typeName, function() use ($retourType) {
55 55
             return $retourType;
56 56
         });
57 57
 
Please login to merge, or discard this patch.
src/controllers/StatisticsController.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         );
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
             Craft::t(
150 150
                 'retour',
151 151
                 'Retour statistics deleted: {error}',
152
-                ['error' => $stickyError]
152
+                [ 'error' => $stickyError ]
153 153
             ),
154 154
             __METHOD__
155 155
         );
Please login to merge, or discard this patch.
src/controllers/TablesController.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $handled = 'all'
97 97
     ): Response {
98 98
         PermissionHelper::controllerPermissionCheck('retour:dashboard');
99
-        $data = [];
99
+        $data = [ ];
100 100
         $sortField = 'hitCount';
101 101
         $sortType = 'DESC';
102 102
         // Figure out the sorting type
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
             }
109 109
         }
110 110
         $sortType = strtoupper($sortType);
111
-        $sortType = self::SORT_MAP[$sortType] ?? self::SORT_MAP['DESC'];
111
+        $sortType = self::SORT_MAP[ $sortType ] ?? self::SORT_MAP[ 'DESC' ];
112 112
         // Validate untrusted data
113 113
         if (!in_array($sortField, self::ALLOWED_STATS_SORT_FIELDS, true)) {
114 114
             throw new BadRequestHttpException(Craft::t('retour', 'Invalid sort field specified.'));
@@ -116,48 +116,48 @@  discard block
 block discarded – undo
116 116
         // Query the db table
117 117
         $offset = ($page - 1) * $per_page;
118 118
         $query = (new Query())
119
-            ->from(['{{%retour_stats}}'])
119
+            ->from([ '{{%retour_stats}}' ])
120 120
             ->offset($offset)
121 121
             ->limit($per_page)
122
-            ->orderBy([$sortField => $sortType]);
123
-        if ((int)$siteId !== 0) {
124
-            $query->where(['siteId' => $siteId]);
122
+            ->orderBy([ $sortField => $sortType ]);
123
+        if ((int) $siteId !== 0) {
124
+            $query->where([ 'siteId' => $siteId ]);
125 125
         }
126 126
         if ($handled !== 'all') {
127
-            $query->where(['handledByRetour' => self::HANDLED_MAP[$handled]]);
127
+            $query->where([ 'handledByRetour' => self::HANDLED_MAP[ $handled ] ]);
128 128
         }
129 129
         if ($filter !== '') {
130
-            $query->where(['like', 'redirectSrcUrl', $filter]);
131
-            $query->orWhere(['like', 'referrerUrl', $filter]);
130
+            $query->where([ 'like', 'redirectSrcUrl', $filter ]);
131
+            $query->orWhere([ 'like', 'referrerUrl', $filter ]);
132 132
         }
133 133
         $stats = $query->all();
134 134
         if ($stats) {
135 135
             // Add in the `addLink` field
136 136
             foreach ($stats as &$stat) {
137
-                $stat['addLink'] = '';
138
-                if (!$stat['handledByRetour']) {
139
-                    $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/'));
140
-                    $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [
137
+                $stat[ 'addLink' ] = '';
138
+                if (!$stat[ 'handledByRetour' ]) {
139
+                    $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/'));
140
+                    $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [
141 141
                         'defaultUrl' => $encodedUrl
142 142
                     ]);
143 143
                 }
144 144
             }
145 145
             // Format the data for the API
146
-            $data['data'] = $stats;
146
+            $data[ 'data' ] = $stats;
147 147
             $query = (new Query())
148
-                ->from(['{{%retour_stats}}']);
149
-            if ((int)$siteId !== 0) {
150
-                $query->where(['siteId' => $siteId]);
148
+                ->from([ '{{%retour_stats}}' ]);
149
+            if ((int) $siteId !== 0) {
150
+                $query->where([ 'siteId' => $siteId ]);
151 151
             }
152 152
             if ($handled !== 'all') {
153
-                $query->where(['handledByRetour' => self::HANDLED_MAP[$handled]]);
153
+                $query->where([ 'handledByRetour' => self::HANDLED_MAP[ $handled ] ]);
154 154
             }
155 155
             if ($filter !== '') {
156
-                $query->where(['like', 'redirectSrcUrl', $filter]);
157
-                $query->orWhere(['like', 'referrerUrl', $filter]);
156
+                $query->where([ 'like', 'redirectSrcUrl', $filter ]);
157
+                $query->orWhere([ 'like', 'referrerUrl', $filter ]);
158 158
             }
159 159
             $count = $query->count();
160
-            $data['links']['pagination'] = [
160
+            $data[ 'links' ][ 'pagination' ] = [
161 161
                 'total' => $count,
162 162
                 'per_page' => $per_page,
163 163
                 'current_page' => $page,
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         $siteId = 0
194 194
     ): Response {
195 195
         PermissionHelper::controllerPermissionCheck('retour:redirects');
196
-        $data = [];
196
+        $data = [ ];
197 197
         $sortField = 'hitCount';
198 198
         $sortType = 'DESC';
199 199
         // Figure out the sorting type
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
             }
206 206
         }
207 207
         $sortType = strtoupper($sortType);
208
-        $sortType = self::SORT_MAP[$sortType] ?? self::SORT_MAP['DESC'];
208
+        $sortType = self::SORT_MAP[ $sortType ] ?? self::SORT_MAP[ 'DESC' ];
209 209
         // Validate untrusted data
210 210
         if (!in_array($sortField, self::ALLOWED_REDIRECTS_SORT_FIELDS, true)) {
211 211
             throw new BadRequestHttpException(Craft::t('retour', 'Invalid sort field specified.'));
@@ -213,52 +213,52 @@  discard block
 block discarded – undo
213 213
         // Query the db table
214 214
         $offset = ($page - 1) * $per_page;
215 215
         $query = (new Query())
216
-            ->from(['{{%retour_static_redirects}}'])
216
+            ->from([ '{{%retour_static_redirects}}' ])
217 217
             ->offset($offset)
218 218
             ->limit($per_page)
219
-            ->orderBy([$sortField => $sortType]);
220
-        if ((int)$siteId !== 0) {
221
-            $query->where(['siteId' => $siteId]);
219
+            ->orderBy([ $sortField => $sortType ]);
220
+        if ((int) $siteId !== 0) {
221
+            $query->where([ 'siteId' => $siteId ]);
222 222
         }
223 223
         if ($filter !== '') {
224
-            $query->where(['like', 'redirectSrcUrl', $filter]);
225
-            $query->orWhere(['like', 'redirectDestUrl', $filter]);
224
+            $query->where([ 'like', 'redirectSrcUrl', $filter ]);
225
+            $query->orWhere([ 'like', 'redirectDestUrl', $filter ]);
226 226
         }
227 227
         $redirects = $query->all();
228 228
         // Add in the `deleteLink` field and clean up the redirects
229 229
         foreach ($redirects as &$redirect) {
230 230
             // Make sure the destination URL is not a regex
231
-            if ($redirect['redirectMatchType'] !== 'exactmatch') {
232
-                if (preg_match("/\$\d+/", $redirect['redirectDestUrl'])) {
233
-                    $redirect['redirectDestUrl'] = '';
231
+            if ($redirect[ 'redirectMatchType' ] !== 'exactmatch') {
232
+                if (preg_match("/\$\d+/", $redirect[ 'redirectDestUrl' ])) {
233
+                    $redirect[ 'redirectDestUrl' ] = '';
234 234
                 }
235 235
             }
236 236
             // Handle extracting the site name
237
-            $redirect['siteName'] = Craft::t('retour', 'All Sites');
238
-            if ($redirect['siteId']) {
237
+            $redirect[ 'siteName' ] = Craft::t('retour', 'All Sites');
238
+            if ($redirect[ 'siteId' ]) {
239 239
                 $sites = Craft::$app->getSites();
240
-                $site = $sites->getSiteById($redirect['siteId']);
240
+                $site = $sites->getSiteById($redirect[ 'siteId' ]);
241 241
                 if ($site) {
242
-                    $redirect['siteName'] = $site->name;
242
+                    $redirect[ 'siteName' ] = $site->name;
243 243
                 }
244 244
             }
245 245
 
246
-            $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']);
246
+            $redirect[ 'editLink' ] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]);
247 247
         }
248 248
         // Format the data for the API
249 249
         if ($redirects) {
250
-            $data['data'] = $redirects;
250
+            $data[ 'data' ] = $redirects;
251 251
             $query = (new Query())
252
-                ->from(['{{%retour_static_redirects}}']);
253
-            if ((int)$siteId !== 0) {
254
-                $query->where(['siteId' => $siteId]);
252
+                ->from([ '{{%retour_static_redirects}}' ]);
253
+            if ((int) $siteId !== 0) {
254
+                $query->where([ 'siteId' => $siteId ]);
255 255
             }
256 256
             if ($filter !== '') {
257
-                $query->where(['like', 'redirectSrcUrl', $filter]);
258
-                $query->orWhere(['like', 'redirectDestUrl', $filter]);
257
+                $query->where([ 'like', 'redirectSrcUrl', $filter ]);
258
+                $query->orWhere([ 'like', 'redirectDestUrl', $filter ]);
259 259
             }
260 260
             $count = $query->count();
261
-            $data['links']['pagination'] = [
261
+            $data[ 'links' ][ 'pagination' ] = [
262 262
                 'total' => $count,
263 263
                 'per_page' => $per_page,
264 264
                 'current_page' => $page,
Please login to merge, or discard this patch.
src/controllers/RedirectsController.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     // Protected Properties
42 42
     // =========================================================================
43 43
 
44
-    protected $allowAnonymous = [];
44
+    protected $allowAnonymous = [ ];
45 45
 
46 46
     // Public Methods
47 47
     // =========================================================================
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function actionRedirects(string $siteHandle = null): Response
59 59
     {
60
-        $variables = [];
60
+        $variables = [ ];
61 61
         PermissionHelper::controllerPermissionCheck('retour:redirects');
62 62
         // Get the site to edit
63 63
         $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle);
@@ -70,32 +70,32 @@  discard block
 block discarded – undo
70 70
         } catch (InvalidConfigException $e) {
71 71
             Craft::error($e->getMessage(), __METHOD__);
72 72
         }
73
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
73
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
74 74
             '@nystudio107/retour/assetbundles/retour/dist',
75 75
             true
76 76
         );
77 77
         // Enabled sites
78 78
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
79
-        $variables['controllerHandle'] = 'redirects';
79
+        $variables[ 'controllerHandle' ] = 'redirects';
80 80
 
81 81
         // Basic variables
82
-        $variables['fullPageForm'] = false;
83
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
84
-        $variables['pluginName'] = $pluginName;
85
-        $variables['title'] = $templateTitle;
86
-        $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : '';
87
-        $variables['crumbs'] = [
82
+        $variables[ 'fullPageForm' ] = false;
83
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
84
+        $variables[ 'pluginName' ] = $pluginName;
85
+        $variables[ 'title' ] = $templateTitle;
86
+        $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : '';
87
+        $variables[ 'crumbs' ] = [
88 88
             [
89 89
                 'label' => $pluginName,
90 90
                 'url' => UrlHelper::cpUrl('retour'),
91 91
             ],
92 92
             [
93 93
                 'label' => $templateTitle,
94
-                'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri),
94
+                'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri),
95 95
             ],
96 96
         ];
97
-        $variables['docTitle'] = "{$pluginName} - {$templateTitle}";
98
-        $variables['selectedSubnavItem'] = 'redirects';
97
+        $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}";
98
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
99 99
 
100 100
         // Render the template
101 101
         return $this->renderTemplate('retour/redirects/index', $variables);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         int $siteId = 0,
120 120
         StaticRedirectsModel $redirect = null
121 121
     ): Response {
122
-        $variables = [];
122
+        $variables = [ ];
123 123
         PermissionHelper::controllerPermissionCheck('retour:redirects');
124 124
 
125 125
         // Load in the redirect
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
         if ($redirect === null) {
134 134
             $redirectConfig = Retour::$plugin->redirects->getRedirectById($redirectId);
135 135
             if ($redirectConfig === null) {
136
-                $redirectConfig = [];
136
+                $redirectConfig = [ ];
137 137
                 Craft::error(
138 138
                     Craft::t(
139 139
                         'retour',
140 140
                         "Couldn't load redirect id {id}",
141
-                        ['id' => $redirectId]
141
+                        [ 'id' => $redirectId ]
142 142
                     ),
143 143
                     __METHOD__
144 144
                 );
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
         if ($redirect->siteId) {
152 152
             $site = $sites->getSiteById($redirect->siteId);
153 153
             if ($site) {
154
-                MultiSiteHelper::requirePermission('editSite:'.$site->uid);
154
+                MultiSiteHelper::requirePermission('editSite:' . $site->uid);
155 155
             }
156 156
         }
157 157
         if ($siteId) {
158 158
             $site = $sites->getSiteById($siteId);
159 159
             if ($site) {
160
-                MultiSiteHelper::requirePermission('editSite:'.$site->uid);
160
+                MultiSiteHelper::requirePermission('editSite:' . $site->uid);
161 161
             }
162 162
         }
163 163
         $pluginName = Retour::$settings->pluginName;
@@ -169,20 +169,20 @@  discard block
 block discarded – undo
169 169
         } catch (InvalidConfigException $e) {
170 170
             Craft::error($e->getMessage(), __METHOD__);
171 171
         }
172
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
172
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
173 173
             '@nystudio107/retour/assetbundles/retour/dist',
174 174
             true
175 175
         );
176 176
         // Sites menu
177 177
         MultiSiteHelper::setSitesMenuVariables($variables);
178
-        $variables['controllerHandle'] = 'redirects';
178
+        $variables[ 'controllerHandle' ] = 'redirects';
179 179
 
180 180
         // Basic variables
181
-        $variables['fullPageForm'] = true;
182
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
183
-        $variables['pluginName'] = $pluginName;
184
-        $variables['title'] = $templateTitle;
185
-        $variables['crumbs'] = [
181
+        $variables[ 'fullPageForm' ] = true;
182
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
183
+        $variables[ 'pluginName' ] = $pluginName;
184
+        $variables[ 'title' ] = $templateTitle;
185
+        $variables[ 'crumbs' ] = [
186 186
             [
187 187
                 'label' => $pluginName,
188 188
                 'url' => UrlHelper::cpUrl('retour'),
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
             ],
194 194
             [
195 195
                 'label' => $templateTitle,
196
-                'url' => UrlHelper::cpUrl('retour/edit-redirect/'.$redirectId),
196
+                'url' => UrlHelper::cpUrl('retour/edit-redirect/' . $redirectId),
197 197
             ],
198 198
         ];
199
-        $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}";
200
-        $variables['selectedSubnavItem'] = 'redirects';
201
-        $variables['redirect'] = $redirect;
199
+        $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}";
200
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
201
+        $variables[ 'redirect' ] = $redirect;
202 202
 
203 203
         // Render the template
204 204
         return $this->renderTemplate('retour/redirects/_edit', $variables);
@@ -251,12 +251,12 @@  discard block
 block discarded – undo
251 251
         if ($redirectConfig === null) {
252 252
             throw new NotFoundHttpException('Redirect not found');
253 253
         }
254
-        $redirectConfig['id'] = (int)$redirectConfig['id'];
254
+        $redirectConfig[ 'id' ] = (int) $redirectConfig[ 'id' ];
255 255
         // Handle enforcing trailing slashes
256 256
         $generalConfig = Craft::$app->getConfig()->getGeneral();
257 257
         if ($generalConfig->addTrailingSlashesToUrls) {
258
-            $destUrl = $redirectConfig['redirectDestUrl'] ?? '';
259
-            $redirectConfig['redirectDestUrl'] = $this->addSlashToSiteUrls($destUrl);
258
+            $destUrl = $redirectConfig[ 'redirectDestUrl' ] ?? '';
259
+            $redirectConfig[ 'redirectDestUrl' ] = $this->addSlashToSiteUrls($destUrl);
260 260
         }
261 261
         $redirect = new StaticRedirectsModel($redirectConfig);
262 262
         // Make sure the redirect validates
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
         Retour::$plugin->redirects->saveRedirect($redirectConfig);
275 275
         // Handle the case where the redirect wasn't saved because it'd create a redirect loop
276 276
         $testRedirectConfig = Retour::$plugin->redirects->getRedirectByRedirectSrcUrl(
277
-            $redirectConfig['redirectSrcUrl'],
278
-            $redirectConfig['siteId']
277
+            $redirectConfig[ 'redirectSrcUrl' ],
278
+            $redirectConfig[ 'siteId' ]
279 279
         );
280 280
         if ($testRedirectConfig === null) {
281 281
             Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save redirect settings because it'd create a redirect loop."));
Please login to merge, or discard this patch.
src/helpers/UrlHelper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
         /** @noinspection CallableParameterUseCaseInTypeContextInspection */
40 40
         $url = preg_replace('/{.*}/', '', $url);
41 41
         // Remove any linebreaks that may be errantly in the URL
42
-        $url = (string)str_replace(PHP_EOL, '', $url);
42
+        $url = (string) str_replace(PHP_EOL, '', $url);
43 43
 
44 44
         return $url;
45 45
     }
Please login to merge, or discard this patch.
src/services/Redirects.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,13 +214,13 @@  discard block
 block discarded – undo
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
-                    $siteId = $redirect['siteId'] ?? null;
221
+                    $siteId = $redirect[ 'siteId' ] ?? null;
222 222
                     if ($siteId !== null) {
223
-                        $siteId = (int)$siteId;
223
+                        $siteId = (int) $siteId;
224 224
                     }
225 225
                     $dest = UrlHelper::siteUrl($dest, null, null, $siteId);
226 226
                 } catch (\yii\base\Exception $e) {
@@ -232,17 +232,17 @@  discard block
 block discarded – undo
232 232
                     $dest .= '?' . $request->getQueryStringWithoutPath();
233 233
                 }
234 234
             }
235
-            $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound';
235
+            $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound';
236 236
             // Parse reference tags for exact matches
237 237
             if ($redirectMatchType === 'exactmatch') {
238
-                $dest = Craft::$app->elements->parseRefs($dest, $redirect['siteId'] ?? null);
238
+                $dest = Craft::$app->elements->parseRefs($dest, $redirect[ 'siteId' ] ?? null);
239 239
             }
240
-            $status = $redirect['redirectHttpCode'];
240
+            $status = $redirect[ 'redirectHttpCode' ];
241 241
             Craft::info(
242 242
                 Craft::t(
243 243
                     'retour',
244 244
                     'Redirecting {url} to {dest} with status {status}',
245
-                    ['url' => $url, 'dest' => $dest, 'status' => $status]
245
+                    [ 'url' => $url, 'dest' => $dest, 'status' => $status ]
246 246
                 ),
247 247
                 __METHOD__
248 248
             );
@@ -326,13 +326,13 @@  discard block
 block discarded – undo
326 326
     public function getRedirectFromCache($url, int $siteId = 0)
327 327
     {
328 328
         $cache = Craft::$app->getCache();
329
-        $cacheKey = $this::CACHE_KEY.md5($url).$siteId;
329
+        $cacheKey = $this::CACHE_KEY . md5($url) . $siteId;
330 330
         $redirect = $cache->get($cacheKey);
331 331
         Craft::info(
332 332
             Craft::t(
333 333
                 'retour',
334 334
                 'Cached redirect hit for {url}',
335
-                ['url' => $url]
335
+                [ 'url' => $url ]
336 336
             ),
337 337
             __METHOD__
338 338
         );
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
         } catch (SiteNotFoundException $e) {
355 355
             $siteId = 1;
356 356
         }
357
-        $cacheKey = $this::CACHE_KEY.md5($url).$siteId;
357
+        $cacheKey = $this::CACHE_KEY . md5($url) . $siteId;
358 358
         // Create the dependency tags
359 359
         $dependency = new TagDependency([
360 360
             'tags' => [
361 361
                 $this::GLOBAL_REDIRECTS_CACHE_TAG,
362
-                $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId,
362
+                $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId,
363 363
             ],
364 364
         ]);
365 365
         $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency);
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
             Craft::t(
368 368
                 'retour',
369 369
                 'Cached redirect saved for {url}',
370
-                ['url' => $url]
370
+                [ 'url' => $url ]
371 371
             ),
372 372
             __METHOD__
373 373
         );
@@ -397,8 +397,8 @@  discard block
 block discarded – undo
397 397
         // Iterate through the redirects
398 398
         foreach ($redirects as $redirect) {
399 399
             // Figure out what type of source matching to do
400
-            $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly';
401
-            $redirectEnabled = (bool)$redirect['enabled'];
400
+            $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly';
401
+            $redirectEnabled = (bool) $redirect[ 'enabled' ];
402 402
             if ($redirectEnabled === true) {
403 403
                 switch ($redirectSrcMatch) {
404 404
                     case 'pathonly':
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
                         $url = $pathOnly;
412 412
                         break;
413 413
                 }
414
-                $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound';
414
+                $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound';
415 415
                 switch ($redirectMatchType) {
416 416
                     // Do a straight up match
417 417
                     case 'exactmatch':
418
-                        if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) {
418
+                        if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) {
419 419
                             $this->incrementRedirectHitCount($redirect);
420 420
                             $this->saveRedirectToCache($url, $redirect);
421 421
 
@@ -425,15 +425,15 @@  discard block
 block discarded – undo
425 425
 
426 426
                     // Do a regex match
427 427
                     case 'regexmatch':
428
-                        $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i';
428
+                        $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i';
429 429
                         try {
430 430
                             if (preg_match($matchRegEx, $url) === 1) {
431 431
                                 $this->incrementRedirectHitCount($redirect);
432 432
                                 // If we're not associated with an EntryID, handle capture group replacement
433
-                                if ((int)$redirect['associatedElementId'] === 0) {
434
-                                    $redirect['redirectDestUrl'] = preg_replace(
433
+                                if ((int) $redirect[ 'associatedElementId' ] === 0) {
434
+                                    $redirect[ 'redirectDestUrl' ] = preg_replace(
435 435
                                         $matchRegEx,
436
-                                        $redirect['redirectDestUrl'],
436
+                                        $redirect[ 'redirectDestUrl' ],
437 437
                                         $url
438 438
                                     );
439 439
                                 }
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
                             }
445 445
                         } catch (\Exception $e) {
446 446
                             // That's fine
447
-                            Craft::error('Invalid Redirect Regex: '.$matchRegEx, __METHOD__);
447
+                            Craft::error('Invalid Redirect Regex: ' . $matchRegEx, __METHOD__);
448 448
                         }
449 449
 
450 450
                         break;
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
                                     'redirect' => &$redirect,
459 459
                                 ],
460 460
                             ];
461
-                            $result = \call_user_func_array([$plugin, 'retourMatch'], $args);
461
+                            $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args);
462 462
                             if ($result) {
463 463
                                 $this->incrementRedirectHitCount($redirect);
464 464
                                 $this->saveRedirectToCache($url, $redirect);
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
             Craft::t(
486 486
                 'retour',
487 487
                 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}',
488
-                ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly]
488
+                [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ]
489 489
             ),
490 490
             __METHOD__
491 491
         );
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
         foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) {
531 531
             /** @var Plugin $plugin */
532 532
             if (method_exists($plugin, 'retourMatch')) {
533
-                $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match');
533
+                $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match');
534 534
             }
535 535
         }
536 536
 
@@ -551,12 +551,12 @@  discard block
 block discarded – undo
551 551
         }
552 552
         // Query the db table
553 553
         $query = (new Query())
554
-            ->from(['{{%retour_static_redirects}}'])
554
+            ->from([ '{{%retour_static_redirects}}' ])
555 555
             ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC');
556 556
         if ($siteId) {
557 557
             $query
558
-                ->where(['siteId' => $siteId])
559
-                ->orWhere(['siteId' => null]);
558
+                ->where([ 'siteId' => $siteId ])
559
+                ->orWhere([ 'siteId' => null ]);
560 560
         }
561 561
         if ($limit) {
562 562
             $query->limit($limit);
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
     {
580 580
         // Query the db table
581 581
         $redirect = (new Query())
582
-            ->from(['{{%retour_static_redirects}}'])
583
-            ->where(['id' => $id])
582
+            ->from([ '{{%retour_static_redirects}}' ])
583
+            ->where([ 'id' => $id ])
584 584
             ->one();
585 585
 
586 586
         return $redirect;
@@ -598,16 +598,16 @@  discard block
 block discarded – undo
598 598
     {
599 599
         // Query the db table
600 600
         $query = (new Query())
601
-            ->from(['{{%retour_static_redirects}}'])
602
-            ->where(['redirectSrcUrl' => $redirectSrcUrl])
601
+            ->from([ '{{%retour_static_redirects}}' ])
602
+            ->where([ 'redirectSrcUrl' => $redirectSrcUrl ])
603 603
             ;
604 604
         if ($siteId) {
605 605
             $query
606
-                ->andWhere(['or', [
606
+                ->andWhere([ 'or', [
607 607
                     'siteId' => $siteId,
608 608
                 ], [
609 609
                     'siteId' => null,
610
-                ]]);
610
+                ] ]);
611 611
         }
612 612
         $redirect = $query->one();
613 613
 
@@ -649,13 +649,13 @@  discard block
 block discarded – undo
649 649
     {
650 650
         if ($redirectConfig !== null) {
651 651
             $db = Craft::$app->getDb();
652
-            $redirectConfig['hitCount']++;
653
-            $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime());
652
+            $redirectConfig[ 'hitCount' ]++;
653
+            $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime());
654 654
             Craft::debug(
655 655
                 Craft::t(
656 656
                     'retour',
657 657
                     'Incrementing statistics for: {redirect}',
658
-                    ['redirect' => print_r($redirectConfig, true)]
658
+                    [ 'redirect' => print_r($redirectConfig, true) ]
659 659
                 ),
660 660
                 __METHOD__
661 661
             );
@@ -664,14 +664,14 @@  discard block
 block discarded – undo
664 664
                 $rowsAffected = $db->createCommand()->update(
665 665
                     '{{%retour_static_redirects}}',
666 666
                     [
667
-                        'hitCount' => $redirectConfig['hitCount'],
668
-                        'hitLastTime' => $redirectConfig['hitLastTime'],
667
+                        'hitCount' => $redirectConfig[ 'hitCount' ],
668
+                        'hitLastTime' => $redirectConfig[ 'hitLastTime' ],
669 669
                     ],
670 670
                     [
671
-                        'id' => $redirectConfig['id'],
671
+                        'id' => $redirectConfig[ 'id' ],
672 672
                     ]
673 673
                 )->execute();
674
-                Craft::debug('Rows affected: '.$rowsAffected, __METHOD__);
674
+                Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__);
675 675
             } catch (\Exception $e) {
676 676
                 Craft::error($e->getMessage(), __METHOD__);
677 677
             }
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
                 Craft::t(
691 691
                     'retour',
692 692
                     'Error validating redirect {id}: {errors}',
693
-                    ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)]
693
+                    [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ]
694 694
                 ),
695 695
                 __METHOD__
696 696
             );
@@ -700,32 +700,32 @@  discard block
 block discarded – undo
700 700
         // Get the validated model attributes and save them to the db
701 701
         $redirectConfig = $redirect->getAttributes();
702 702
         // 0 for a siteId needs to be converted to null
703
-        if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) {
704
-            $redirectConfig['siteId'] = null;
703
+        if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) {
704
+            $redirectConfig[ 'siteId' ] = null;
705 705
         }
706 706
         // Throw an event to before saving the redirect
707 707
         $db = Craft::$app->getDb();
708 708
         // See if a redirect exists with this source URL already
709
-        if ((int)$redirectConfig['id'] === 0) {
709
+        if ((int) $redirectConfig[ 'id' ] === 0) {
710 710
             // Query the db table
711 711
             $redirect = (new Query())
712
-                ->from(['{{%retour_static_redirects}}'])
713
-                ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']])
714
-                ->andWhere(['siteId' => $redirectConfig['siteId']])
712
+                ->from([ '{{%retour_static_redirects}}' ])
713
+                ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ])
714
+                ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ])
715 715
                 ->one();
716 716
             // If it exists, update it rather than having duplicates
717 717
             if (!empty($redirect)) {
718
-                $redirectConfig['id'] = $redirect['id'];
718
+                $redirectConfig[ 'id' ] = $redirect[ 'id' ];
719 719
             }
720 720
         }
721 721
         // Trigger a 'beforeSaveRedirect' event
722
-        $isNew = (int)$redirectConfig['id'] === 0;
722
+        $isNew = (int) $redirectConfig[ 'id' ] === 0;
723 723
         $event = new RedirectEvent([
724 724
             'isNew' => $isNew,
725
-            'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'],
726
-            'destinationUrl' => $redirectConfig['redirectDestUrl'],
727
-            'matchType' => $redirectConfig['redirectSrcMatch'],
728
-            'redirectType' => $redirectConfig['redirectHttpCode'],
725
+            'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ],
726
+            'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ],
727
+            'matchType' => $redirectConfig[ 'redirectSrcMatch' ],
728
+            'redirectType' => $redirectConfig[ 'redirectHttpCode' ],
729 729
         ]);
730 730
         $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event);
731 731
         if (!$event->isValid) {
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
                 Craft::t(
738 738
                     'retour',
739 739
                     'Updating existing redirect: {redirect}',
740
-                    ['redirect' => print_r($redirectConfig, true)]
740
+                    [ 'redirect' => print_r($redirectConfig, true) ]
741 741
                 ),
742 742
                 __METHOD__
743 743
             );
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
                     '{{%retour_static_redirects}}',
748 748
                     $redirectConfig,
749 749
                     [
750
-                        'id' => $redirectConfig['id'],
750
+                        'id' => $redirectConfig[ 'id' ],
751 751
                     ]
752 752
                 )->execute();
753 753
             } catch (Exception $e) {
@@ -758,11 +758,11 @@  discard block
 block discarded – undo
758 758
                 Craft::t(
759 759
                     'retour',
760 760
                     'Creating new redirect: {redirect}',
761
-                    ['redirect' => print_r($redirectConfig, true)]
761
+                    [ 'redirect' => print_r($redirectConfig, true) ]
762 762
                 ),
763 763
                 __METHOD__
764 764
             );
765
-            unset($redirectConfig['id']);
765
+            unset($redirectConfig[ 'id' ]);
766 766
             // Create a new record
767 767
             try {
768 768
                 $db->createCommand()->insert(
@@ -775,15 +775,15 @@  discard block
 block discarded – undo
775 775
         }
776 776
         // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl
777 777
         $testRedirectConfig = $this->getRedirectByRedirectSrcUrl(
778
-            $redirectConfig['redirectDestUrl'],
779
-            $redirectConfig['siteId']
778
+            $redirectConfig[ 'redirectDestUrl' ],
779
+            $redirectConfig[ 'siteId' ]
780 780
         );
781 781
         if ($testRedirectConfig !== null) {
782 782
             Craft::debug(
783 783
                 Craft::t(
784 784
                     'retour',
785 785
                     'Deleting redirect to prevent a loop: {redirect}',
786
-                    ['redirect' => print_r($testRedirectConfig, true)]
786
+                    [ 'redirect' => print_r($testRedirectConfig, true) ]
787 787
                 ),
788 788
                 __METHOD__
789 789
             );
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
             try {
792 792
                 $db->createCommand()->delete(
793 793
                     '{{%retour_static_redirects}}',
794
-                    ['id' => $testRedirectConfig['id']]
794
+                    [ 'id' => $testRedirectConfig[ 'id' ] ]
795 795
                 )->execute();
796 796
             } catch (Exception $e) {
797 797
                 Craft::error($e->getMessage(), __METHOD__);
@@ -824,17 +824,17 @@  discard block
 block discarded – undo
824 824
      */
825 825
     public function excludeUri($uri): bool
826 826
     {
827
-        $uri = '/'.ltrim($uri, '/');
827
+        $uri = '/' . ltrim($uri, '/');
828 828
         if (!empty(Retour::$settings->excludePatterns)) {
829 829
             foreach (Retour::$settings->excludePatterns as $excludePattern) {
830
-                $pattern = '`'.$excludePattern['pattern'].'`i';
830
+                $pattern = '`' . $excludePattern[ 'pattern' ] . '`i';
831 831
                 try {
832 832
                     if (preg_match($pattern, $uri) === 1) {
833 833
                         return true;
834 834
                     }
835 835
                 } catch (\Exception $e) {
836 836
                     // That's fine
837
-                    Craft::error('Invalid exclude URI Regex: '.$pattern, __METHOD__);
837
+                    Craft::error('Invalid exclude URI Regex: ' . $pattern, __METHOD__);
838 838
                 }
839 839
             }
840 840
         }
Please login to merge, or discard this patch.