Passed
Push — v3 ( 89cbc4...a19b86 )
by Andrew
13:39 queued 08:47
created
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.