@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $handled = 'all' |
| 98 | 98 | ): Response { |
| 99 | 99 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
| 100 | - $data = []; |
|
| 100 | + $data = [ ]; |
|
| 101 | 101 | $sortField = 'hitCount'; |
| 102 | 102 | $sortType = 'DESC'; |
| 103 | 103 | // Figure out the sorting type |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | $sortType = strtoupper($sortType); |
| 112 | - $sortType = self::SORT_MAP[$sortType] ?? self::SORT_MAP['DESC']; |
|
| 112 | + $sortType = self::SORT_MAP[ $sortType ] ?? self::SORT_MAP[ 'DESC' ]; |
|
| 113 | 113 | // Validate untrusted data |
| 114 | 114 | if (!in_array($sortField, self::ALLOWED_STATS_SORT_FIELDS, true)) { |
| 115 | 115 | throw new BadRequestHttpException(Craft::t('retour', 'Invalid sort field specified.')); |
@@ -117,46 +117,46 @@ discard block |
||
| 117 | 117 | // Query the db table |
| 118 | 118 | $offset = ($page - 1) * $per_page; |
| 119 | 119 | $query = (new Query()) |
| 120 | - ->from(['{{%retour_stats}}']) |
|
| 120 | + ->from([ '{{%retour_stats}}' ]) |
|
| 121 | 121 | ->offset($offset) |
| 122 | 122 | ->limit($per_page) |
| 123 | - ->orderBy([$sortField => $sortType]) |
|
| 124 | - ->filterWhere(['like', 'redirectSrcUrl', $filter]) |
|
| 125 | - ->orFilterWhere(['like', 'referrerUrl', $filter]) |
|
| 123 | + ->orderBy([ $sortField => $sortType ]) |
|
| 124 | + ->filterWhere([ 'like', 'redirectSrcUrl', $filter ]) |
|
| 125 | + ->orFilterWhere([ 'like', 'referrerUrl', $filter ]) |
|
| 126 | 126 | ; |
| 127 | - if ((int)$siteId !== 0) { |
|
| 128 | - $query->andWhere(['siteId' => $siteId]); |
|
| 127 | + if ((int) $siteId !== 0) { |
|
| 128 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
| 129 | 129 | } |
| 130 | 130 | if ($handled !== 'all') { |
| 131 | - $query->andWhere(['handledByRetour' => self::HANDLED_MAP[$handled]]); |
|
| 131 | + $query->andWhere([ 'handledByRetour' => self::HANDLED_MAP[ $handled ] ]); |
|
| 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'], '/')); |
|
| 137 | + $stat[ 'addLink' ] = ''; |
|
| 138 | + if (!$stat[ 'handledByRetour' ]) { |
|
| 139 | + $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/')); |
|
| 140 | 140 | // Add the siteId to the URL, but keep the current behavior of passing in siteId=0 for "all" |
| 141 | - $statSiteId = $stat['siteId'] ?? 0; |
|
| 141 | + $statSiteId = $stat[ 'siteId' ] ?? 0; |
|
| 142 | 142 | try { |
| 143 | 143 | $primarySite = Craft::$app->getSites()->getPrimarySite(); |
| 144 | 144 | } catch (SiteNotFoundException $e) { |
| 145 | 145 | $primarySite = null; |
| 146 | 146 | } |
| 147 | - if ($primarySite !== null && $statSiteId == (int)$primarySite->id) { |
|
| 147 | + if ($primarySite !== null && $statSiteId == (int) $primarySite->id) { |
|
| 148 | 148 | $statSiteId = 0; |
| 149 | 149 | } |
| 150 | - $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
| 150 | + $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
| 151 | 151 | 'defaultUrl' => $encodedUrl, |
| 152 | 152 | 'siteId' => $statSiteId |
| 153 | 153 | ]); |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | // Format the data for the API |
| 157 | - $data['data'] = $stats; |
|
| 157 | + $data[ 'data' ] = $stats; |
|
| 158 | 158 | $count = $query->count(); |
| 159 | - $data['links']['pagination'] = [ |
|
| 159 | + $data[ 'links' ][ 'pagination' ] = [ |
|
| 160 | 160 | 'total' => $count, |
| 161 | 161 | 'per_page' => $per_page, |
| 162 | 162 | 'current_page' => $page, |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $siteId = 0 |
| 193 | 193 | ): Response { |
| 194 | 194 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
| 195 | - $data = []; |
|
| 195 | + $data = [ ]; |
|
| 196 | 196 | $sortField = 'hitCount'; |
| 197 | 197 | $sortType = 'DESC'; |
| 198 | 198 | // Figure out the sorting type |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | $sortType = strtoupper($sortType); |
| 207 | - $sortType = self::SORT_MAP[$sortType] ?? self::SORT_MAP['DESC']; |
|
| 207 | + $sortType = self::SORT_MAP[ $sortType ] ?? self::SORT_MAP[ 'DESC' ]; |
|
| 208 | 208 | // Validate untrusted data |
| 209 | 209 | if (!in_array($sortField, self::ALLOWED_REDIRECTS_SORT_FIELDS, true)) { |
| 210 | 210 | throw new BadRequestHttpException(Craft::t('retour', 'Invalid sort field specified.')); |
@@ -212,42 +212,42 @@ discard block |
||
| 212 | 212 | // Query the db table |
| 213 | 213 | $offset = ($page - 1) * $per_page; |
| 214 | 214 | $query = (new Query()) |
| 215 | - ->from(['{{%retour_static_redirects}}']) |
|
| 215 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 216 | 216 | ->offset($offset) |
| 217 | 217 | ->limit($per_page) |
| 218 | - ->orderBy([$sortField => $sortType]) |
|
| 219 | - ->filterWhere(['like', 'redirectSrcUrl', $filter]) |
|
| 220 | - ->orFilterWhere(['like', 'redirectDestUrl', $filter]) |
|
| 218 | + ->orderBy([ $sortField => $sortType ]) |
|
| 219 | + ->filterWhere([ 'like', 'redirectSrcUrl', $filter ]) |
|
| 220 | + ->orFilterWhere([ 'like', 'redirectDestUrl', $filter ]) |
|
| 221 | 221 | ; |
| 222 | - if ((int)$siteId !== 0) { |
|
| 223 | - $query->andWhere(['siteId' => $siteId]); |
|
| 222 | + if ((int) $siteId !== 0) { |
|
| 223 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
| 224 | 224 | } |
| 225 | 225 | $redirects = $query->all(); |
| 226 | 226 | // Add in the `deleteLink` field and clean up the redirects |
| 227 | 227 | foreach ($redirects as &$redirect) { |
| 228 | 228 | // Make sure the destination URL is not a regex |
| 229 | - if ($redirect['redirectMatchType'] !== 'exactmatch') { |
|
| 230 | - if (preg_match("/\$\d+/", $redirect['redirectDestUrl'])) { |
|
| 231 | - $redirect['redirectDestUrl'] = ''; |
|
| 229 | + if ($redirect[ 'redirectMatchType' ] !== 'exactmatch') { |
|
| 230 | + if (preg_match("/\$\d+/", $redirect[ 'redirectDestUrl' ])) { |
|
| 231 | + $redirect[ 'redirectDestUrl' ] = ''; |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | // Handle extracting the site name |
| 235 | - $redirect['siteName'] = Craft::t('retour', 'All Sites'); |
|
| 236 | - if ($redirect['siteId']) { |
|
| 235 | + $redirect[ 'siteName' ] = Craft::t('retour', 'All Sites'); |
|
| 236 | + if ($redirect[ 'siteId' ]) { |
|
| 237 | 237 | $sites = Craft::$app->getSites(); |
| 238 | - $site = $sites->getSiteById($redirect['siteId']); |
|
| 238 | + $site = $sites->getSiteById($redirect[ 'siteId' ]); |
|
| 239 | 239 | if ($site) { |
| 240 | - $redirect['siteName'] = $site->name; |
|
| 240 | + $redirect[ 'siteName' ] = $site->name; |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']); |
|
| 244 | + $redirect[ 'editLink' ] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]); |
|
| 245 | 245 | } |
| 246 | 246 | // Format the data for the API |
| 247 | 247 | if ($redirects) { |
| 248 | - $data['data'] = $redirects; |
|
| 248 | + $data[ 'data' ] = $redirects; |
|
| 249 | 249 | $count = $query->count(); |
| 250 | - $data['links']['pagination'] = [ |
|
| 250 | + $data[ 'links' ][ 'pagination' ] = [ |
|
| 251 | 251 | 'total' => $count, |
| 252 | 252 | 'per_page' => $per_page, |
| 253 | 253 | 'current_page' => $page, |