Passed
Push — develop ( 8d70c4...0a368d )
by Andrew
04:55
created
src/controllers/RedirectsController.php 1 patch
Spacing   +26 added lines, -26 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,20 +70,20 @@  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
-        $variables['crumbs'] = [
82
+        $variables[ 'fullPageForm' ] = false;
83
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
84
+        $variables[ 'pluginName' ] = $pluginName;
85
+        $variables[ 'title' ] = $templateTitle;
86
+        $variables[ 'crumbs' ] = [
87 87
             [
88 88
                 'label' => $pluginName,
89 89
                 'url' => UrlHelper::cpUrl('retour'),
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
                 'url' => UrlHelper::cpUrl('retour/redirects'),
94 94
             ],
95 95
         ];
96
-        $variables['docTitle'] = "{$pluginName} - {$templateTitle}";
97
-        $variables['selectedSubnavItem'] = 'redirects';
96
+        $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}";
97
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
98 98
 
99 99
         // Render the template
100 100
         return $this->renderTemplate('retour/redirects/index', $variables);
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         string $siteHandle = null,
119 119
         StaticRedirectsModel $redirect = null
120 120
     ): Response {
121
-        $variables = [];
121
+        $variables = [ ];
122 122
         PermissionHelper::controllerPermissionCheck('retour:redirects');
123 123
         // Load in the redirect
124 124
         if ($redirectId === 0) {
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
         if ($redirect === null) {
131 131
             $redirectConfig = Retour::$plugin->redirects->getRedirectById($redirectId);
132 132
             if ($redirectConfig === null) {
133
-                $redirectConfig = [];
133
+                $redirectConfig = [ ];
134 134
                 Craft::error(
135 135
                     Craft::t(
136 136
                         'retour',
137 137
                         "Couldn't load redirect id {id}",
138
-                        ['id' => $redirectId]
138
+                        [ 'id' => $redirectId ]
139 139
                     ),
140 140
                     __METHOD__
141 141
                 );
@@ -153,20 +153,20 @@  discard block
 block discarded – undo
153 153
         } catch (InvalidConfigException $e) {
154 154
             Craft::error($e->getMessage(), __METHOD__);
155 155
         }
156
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
156
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
157 157
             '@nystudio107/retour/assetbundles/retour/dist',
158 158
             true
159 159
         );
160 160
         // Enabled sites
161 161
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
162
-        $variables['controllerHandle'] = 'redirects';
162
+        $variables[ 'controllerHandle' ] = 'redirects';
163 163
 
164 164
         // Basic variables
165
-        $variables['fullPageForm'] = true;
166
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
167
-        $variables['pluginName'] = $pluginName;
168
-        $variables['title'] = $templateTitle;
169
-        $variables['crumbs'] = [
165
+        $variables[ 'fullPageForm' ] = true;
166
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
167
+        $variables[ 'pluginName' ] = $pluginName;
168
+        $variables[ 'title' ] = $templateTitle;
169
+        $variables[ 'crumbs' ] = [
170 170
             [
171 171
                 'label' => $pluginName,
172 172
                 'url' => UrlHelper::cpUrl('retour'),
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
             ],
178 178
             [
179 179
                 'label' => $templateTitle,
180
-                'url' => UrlHelper::cpUrl('retour/edit-redirect/'.$redirectId),
180
+                'url' => UrlHelper::cpUrl('retour/edit-redirect/' . $redirectId),
181 181
             ],
182 182
         ];
183
-        $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}";
184
-        $variables['selectedSubnavItem'] = 'redirects';
185
-        $variables['redirect'] = $redirect;
183
+        $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}";
184
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
185
+        $variables[ 'redirect' ] = $redirect;
186 186
 
187 187
         // Render the template
188 188
         return $this->renderTemplate('retour/redirects/_edit', $variables);
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
         if ($redirectConfig === null) {
229 229
             throw new NotFoundHttpException('Redirect not found');
230 230
         }
231
-        $redirectConfig['id'] = (int)$redirectConfig['id'];
231
+        $redirectConfig[ 'id' ] = (int) $redirectConfig[ 'id' ];
232 232
         $redirect = new StaticRedirectsModel($redirectConfig);
233 233
         // Make sure the redirect validates
234 234
         if (!$redirect->validate()) {
Please login to merge, or discard this patch.
src/models/StaticRedirects.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
     public function rules()
85 85
     {
86 86
         return [
87
-            ['id', 'integer'],
88
-            ['locale', DbStringValidator::class, 'max' => 12],
89
-            ['locale', 'string'],
90
-            ['locale', 'default', 'value' => ''],
91
-            ['associatedElementId', 'default', 'value' => 0],
92
-            ['associatedElementId', 'integer'],
87
+            [ 'id', 'integer' ],
88
+            [ 'locale', DbStringValidator::class, 'max' => 12 ],
89
+            [ 'locale', 'string' ],
90
+            [ 'locale', 'default', 'value' => '' ],
91
+            [ 'associatedElementId', 'default', 'value' => 0 ],
92
+            [ 'associatedElementId', 'integer' ],
93 93
             [
94 94
                 [
95 95
                     'redirectSrcUrl',
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
                 'default',
100 100
                 'value' => ''
101 101
             ],
102
-            ['redirectMatchType', 'default', 'value' => 'exactmatch'],
103
-            ['redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl'],
102
+            [ 'redirectMatchType', 'default', 'value' => 'exactmatch' ],
103
+            [ 'redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl' ],
104 104
             [
105 105
                 [
106 106
                     'redirectSrcUrl',
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
                 ],
129 129
                 'string'
130 130
             ],
131
-            ['redirectHttpCode', 'integer'],
132
-            ['redirectHttpCode', 'default', 'value' => 301],
133
-            ['hitCount', 'default', 'value' => 0],
134
-            ['hitCount', 'integer'],
135
-            ['hitLastTime', 'safe'],
131
+            [ 'redirectHttpCode', 'integer' ],
132
+            [ 'redirectHttpCode', 'default', 'value' => 301 ],
133
+            [ 'hitCount', 'default', 'value' => 0 ],
134
+            [ 'hitCount', 'integer' ],
135
+            [ 'hitLastTime', 'safe' ],
136 136
         ];
137 137
     }
138 138
 }
Please login to merge, or discard this patch.
src/models/Redirects.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
     public function rules()
85 85
     {
86 86
         return [
87
-            ['id', 'integer'],
88
-            ['locale', DbStringValidator::class, 'max' => 12],
89
-            ['locale', 'string'],
90
-            ['locale', 'default', 'value' => ''],
91
-            ['associatedElementId', 'default', 'value' => 0],
92
-            ['associatedElementId', 'integer'],
87
+            [ 'id', 'integer' ],
88
+            [ 'locale', DbStringValidator::class, 'max' => 12 ],
89
+            [ 'locale', 'string' ],
90
+            [ 'locale', 'default', 'value' => '' ],
91
+            [ 'associatedElementId', 'default', 'value' => 0 ],
92
+            [ 'associatedElementId', 'integer' ],
93 93
             [
94 94
                 [
95 95
                     'redirectSrcUrl',
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
                 'default',
100 100
                 'value' => ''
101 101
             ],
102
-            ['redirectMatchType', 'default', 'value' => 'exactmatch'],
103
-            ['redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl'],
102
+            [ 'redirectMatchType', 'default', 'value' => 'exactmatch' ],
103
+            [ 'redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl' ],
104 104
             [
105 105
                 [
106 106
                     'redirectSrcUrl',
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
                 ],
129 129
                 'string'
130 130
             ],
131
-            ['redirectHttpCode', 'integer'],
132
-            ['redirectHttpCode', 'default', 'value' => 301],
133
-            ['hitCount', 'default', 'value' => 0],
134
-            ['hitCount', 'integer'],
135
-            ['hitLastTime', 'safe'],
131
+            [ 'redirectHttpCode', 'integer' ],
132
+            [ 'redirectHttpCode', 'default', 'value' => 301 ],
133
+            [ 'hitCount', 'default', 'value' => 0 ],
134
+            [ 'hitCount', 'integer' ],
135
+            [ 'hitLastTime', 'safe' ],
136 136
         ];
137 137
     }
138 138
 }
Please login to merge, or discard this patch.
src/controllers/FileController.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     // Protected Properties
62 62
     // =========================================================================
63 63
 
64
-    protected $allowAnonymous = [];
64
+    protected $allowAnonymous = [ ];
65 65
 
66 66
     // Public Methods
67 67
     // =========================================================================
@@ -81,21 +81,21 @@  discard block
 block discarded – undo
81 81
         $headers = array_flip($csv->fetchOne(0));
82 82
         $csv->setOffset(1);
83 83
         $columns = ArrayHelper::filterEmptyStringsFromArray($columns);
84
-        $csv->each(function ($row) use ($headers, $columns) {
84
+        $csv->each(function($row) use ($headers, $columns) {
85 85
             $redirectConfig = [
86 86
                 'id' => 0,
87 87
             ];
88
-            if (isset($columns[0], $headers[$columns[0]])) {
89
-                $redirectConfig['redirectSrcUrl'] = $row[$headers[$columns[0]]] ?? null;
88
+            if (isset($columns[ 0 ], $headers[ $columns[ 0 ] ])) {
89
+                $redirectConfig[ 'redirectSrcUrl' ] = $row[ $headers[ $columns[ 0 ] ] ] ?? null;
90 90
             }
91
-            if (isset($columns[1], $headers[$columns[1]])) {
92
-                $redirectConfig['redirectDestUrl'] = $row[$headers[$columns[1]]] ?? null;
91
+            if (isset($columns[ 1 ], $headers[ $columns[ 1 ] ])) {
92
+                $redirectConfig[ 'redirectDestUrl' ] = $row[ $headers[ $columns[ 1 ] ] ] ?? null;
93 93
             }
94
-            if (isset($columns[2], $headers[$columns[2]])) {
95
-                $redirectConfig['redirectMatchType'] = $row[$headers[$columns[2]]] ?? null;
94
+            if (isset($columns[ 2 ], $headers[ $columns[ 2 ] ])) {
95
+                $redirectConfig[ 'redirectMatchType' ] = $row[ $headers[ $columns[ 2 ] ] ] ?? null;
96 96
             }
97
-            if (isset($columns[3], $headers[$columns[3]])) {
98
-                $redirectConfig['redirectHttpCode'] = $row[$headers[$columns[3]]] ?? null;
97
+            if (isset($columns[ 3 ], $headers[ $columns[ 3 ] ])) {
98
+                $redirectConfig[ 'redirectHttpCode' ] = $row[ $headers[ $columns[ 3 ] ] ] ?? null;
99 99
             }
100 100
             Retour::$plugin->redirects->saveRedirect($redirectConfig);
101 101
         });
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function actionImportCsv(string $siteHandle = null): Response
118 118
     {
119
-        $variables = [];
119
+        $variables = [ ];
120 120
         PermissionHelper::controllerPermissionCheck('retour:redirects');
121 121
         // Get the site to edit
122 122
         $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle);
@@ -129,20 +129,20 @@  discard block
 block discarded – undo
129 129
         } catch (InvalidConfigException $e) {
130 130
             Craft::error($e->getMessage(), __METHOD__);
131 131
         }
132
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
132
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
133 133
             '@nystudio107/retour/assetbundles/retour/dist',
134 134
             true
135 135
         );
136 136
         // Enabled sites
137 137
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
138
-        $variables['controllerHandle'] = 'file';
138
+        $variables[ 'controllerHandle' ] = 'file';
139 139
 
140 140
         // Basic variables
141
-        $variables['fullPageForm'] = true;
142
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
143
-        $variables['pluginName'] = $pluginName;
144
-        $variables['title'] = $templateTitle;
145
-        $variables['crumbs'] = [
141
+        $variables[ 'fullPageForm' ] = true;
142
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
143
+        $variables[ 'pluginName' ] = $pluginName;
144
+        $variables[ 'title' ] = $templateTitle;
145
+        $variables[ 'crumbs' ] = [
146 146
             [
147 147
                 'label' => $pluginName,
148 148
                 'url' => UrlHelper::cpUrl('retour'),
@@ -152,19 +152,19 @@  discard block
 block discarded – undo
152 152
                 'url' => UrlHelper::cpUrl('retour/redirects'),
153 153
             ],
154 154
         ];
155
-        $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}";
156
-        $variables['selectedSubnavItem'] = 'redirects';
155
+        $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}";
156
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
157 157
 
158 158
         // The CSV file
159 159
         $file = UploadedFile::getInstanceByName('file');
160 160
         if ($file !== null) {
161
-            $filename = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.uniqid($file->name, true);
161
+            $filename = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . uniqid($file->name, true);
162 162
             $file->saveAs($filename, false);
163 163
             $csv = Reader::createFromPath($file->tempName);
164 164
             $headers = $csv->fetchOne(0);
165 165
             Craft::info(print_r($headers, true), __METHOD__);
166
-            $variables['headers'] = $headers;
167
-            $variables['filename'] = $filename;
166
+            $variables[ 'headers' ] = $headers;
167
+            $variables[ 'filename' ] = $filename;
168 168
         }
169 169
 
170 170
         // Render the template
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
     {
206 206
         // Query the db table
207 207
         $data = (new Query())
208
-            ->from([$table])
208
+            ->from([ $table ])
209 209
             ->select(array_keys($columns))
210 210
             ->orderBy('hitCount DESC')
211 211
             ->all();
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
         $csv = Writer::createFromFileObject(new \SplTempFileObject());
214 214
         $csv->insertOne(array_values($columns));
215 215
         $csv->insertAll($data);
216
-        $csv->output($filename.'.csv');
216
+        $csv->output($filename . '.csv');
217 217
         exit(0);
218 218
     }
219 219
 }
Please login to merge, or discard this patch.
src/controllers/TablesController.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         $filter = ''
60 60
     ): Response {
61 61
         PermissionHelper::controllerPermissionCheck('retour:dashboard');
62
-        $data = [];
62
+        $data = [ ];
63 63
         $sortField = 'hitCount';
64 64
         $sortType = 'DESC';
65 65
         // Figure out the sorting type
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         // Query the db table
74 74
         $offset = ($page - 1) * $per_page;
75 75
         $query = (new Query())
76
-            ->from(['{{%retour_stats}}'])
76
+            ->from([ '{{%retour_stats}}' ])
77 77
             ->offset($offset)
78 78
             ->limit($per_page)
79 79
             ->orderBy("{$sortField} {$sortType}");
@@ -84,22 +84,22 @@  discard block
 block discarded – undo
84 84
         $stats = $query->all();
85 85
         // Add in the `addLink` field
86 86
         foreach ($stats as &$stat) {
87
-            $stat['addLink'] = '';
88
-            if (!$stat['handledByRetour']) {
89
-                $stat['addLink'] = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/'));
87
+            $stat[ 'addLink' ] = '';
88
+            if (!$stat[ 'handledByRetour' ]) {
89
+                $stat[ 'addLink' ] = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/'));
90 90
             }
91 91
         }
92 92
         // Format the data for the API
93 93
         if ($stats) {
94
-            $data['data'] = $stats;
94
+            $data[ 'data' ] = $stats;
95 95
             $query = (new Query())
96
-                ->from(['{{%retour_stats}}']);
96
+                ->from([ '{{%retour_stats}}' ]);
97 97
             if ($filter !== '') {
98 98
                 $query->where("`redirectSrcUrl` LIKE '%{$filter}%'");
99 99
                 $query->orWhere("`referrerUrl` LIKE '%{$filter}%'");
100 100
             }
101 101
             $count = $query->count();
102
-            $data['links']['pagination'] = [
102
+            $data[ 'links' ][ 'pagination' ] = [
103 103
                 'total' => $count,
104 104
                 'per_page' => $per_page,
105 105
                 'current_page' => $page,
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         $filter = ''
133 133
     ): Response {
134 134
         PermissionHelper::controllerPermissionCheck('retour:redirects');
135
-        $data = [];
135
+        $data = [ ];
136 136
         $sortField = 'hitCount';
137 137
         $sortType = 'DESC';
138 138
         // Figure out the sorting type
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         // Query the db table
147 147
         $offset = ($page - 1) * $per_page;
148 148
         $query = (new Query())
149
-            ->from(['{{%retour_static_redirects}}'])
149
+            ->from([ '{{%retour_static_redirects}}' ])
150 150
             ->offset($offset)
151 151
             ->limit($per_page)
152 152
             ->orderBy("{$sortField} {$sortType}");
@@ -157,20 +157,20 @@  discard block
 block discarded – undo
157 157
         $redirects = $query->all();
158 158
         // Add in the `deleteLink` field
159 159
         foreach ($redirects as &$redirect) {
160
-            $redirect['deleteLink'] = $redirect['id'];
161
-            $redirect['redirectSrcUrl'].="|{$redirect['id']}";
160
+            $redirect[ 'deleteLink' ] = $redirect[ 'id' ];
161
+            $redirect[ 'redirectSrcUrl' ] .= "|{$redirect[ 'id' ]}";
162 162
         }
163 163
         // Format the data for the API
164 164
         if ($redirects) {
165
-            $data['data'] = $redirects;
165
+            $data[ 'data' ] = $redirects;
166 166
             $query = (new Query())
167
-                ->from(['{{%retour_static_redirects}}']);
167
+                ->from([ '{{%retour_static_redirects}}' ]);
168 168
             if ($filter !== '') {
169 169
                 $query->where("`redirectSrcUrl` LIKE '%{$filter}%'");
170 170
                 $query->orWhere("`redirectDestUrl` LIKE '%{$filter}%'");
171 171
             }
172 172
             $count = $query->count();
173
-            $data['links']['pagination'] = [
173
+            $data[ 'links' ][ 'pagination' ] = [
174 174
                 'total' => $count,
175 175
                 'per_page' => $per_page,
176 176
                 'current_page' => $page,
Please login to merge, or discard this patch.
src/validators/UriValidator.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
             return;
60 60
         }
61 61
         // Make sure there is a leading /
62
-        $value = '/'.ltrim($value, '/');
62
+        $value = '/' . ltrim($value, '/');
63 63
         $model->$attribute = $value;
64 64
     }
65 65
 }
Please login to merge, or discard this patch.
src/Retour.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     /**
90 90
      * @var array The URIs for the element before it was saved
91 91
      */
92
-    public $oldElementUris = [];
92
+    public $oldElementUris = [ ];
93 93
 
94 94
     // Public Methods
95 95
     // =========================================================================
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             Craft::t(
115 115
                 'retour',
116 116
                 '{name} plugin loaded',
117
-                ['name' => $this->name]
117
+                [ 'name' => $this->name ]
118 118
             ),
119 119
             __METHOD__
120 120
         );
@@ -134,24 +134,24 @@  discard block
 block discarded – undo
134 134
      */
135 135
     public function getCpNavItem()
136 136
     {
137
-        $subNavs = [];
137
+        $subNavs = [ ];
138 138
         $navItem = parent::getCpNavItem();
139 139
         $currentUser = Craft::$app->getUser()->getIdentity();
140 140
         // Only show sub-navs the user has permission to view
141 141
         if ($currentUser->can('retour:dashboard')) {
142
-            $subNavs['dashboard'] = [
142
+            $subNavs[ 'dashboard' ] = [
143 143
                 'label' => 'Dashboard',
144 144
                 'url' => 'retour/dashboard',
145 145
             ];
146 146
         }
147 147
         if ($currentUser->can('retour:redirects')) {
148
-            $subNavs['redirects'] = [
148
+            $subNavs[ 'redirects' ] = [
149 149
                 'label' => 'Redirects',
150 150
                 'url' => 'retour/redirects',
151 151
             ];
152 152
         }
153 153
         if ($currentUser->can('retour:settings')) {
154
-            $subNavs['settings'] = [
154
+            $subNavs[ 'settings' ] = [
155 155
                 'label' => 'Settings',
156 156
                 'url' => 'retour/settings',
157 157
             ];
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         Event::on(
211 211
             Plugins::class,
212 212
             Plugins::EVENT_AFTER_INSTALL_PLUGIN,
213
-            function (PluginEvent $event) {
213
+            function(PluginEvent $event) {
214 214
                 if ($event->plugin === $this) {
215 215
                     // Invalidate our caches after we've been installed
216 216
                     $this->clearAllCaches();
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         Event::on(
238 238
             CraftVariable::class,
239 239
             CraftVariable::EVENT_INIT,
240
-            function (Event $event) {
240
+            function(Event $event) {
241 241
                 /** @var CraftVariable $variable */
242 242
                 $variable = $event->sender;
243 243
                 $variable->set('retour', RetourVariable::class);
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         Event::on(
248 248
             Elements::class,
249 249
             Elements::EVENT_BEFORE_SAVE_ELEMENT,
250
-            function (ElementEvent $event) {
250
+            function(ElementEvent $event) {
251 251
                 Craft::debug(
252 252
                     'Elements::EVENT_BEFORE_SAVE_ELEMENT',
253 253
                     __METHOD__
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
                         if ($oldElement !== null) {
263 263
                             // Stash the old URLs by element id, and do so only once,
264 264
                             // in case we are called more than once per request
265
-                            if (empty($this->oldElementUris[$oldElement->id])) {
266
-                                $this->oldElementUris[$oldElement->id] = $this->getAllElementUris($oldElement);
265
+                            if (empty($this->oldElementUris[ $oldElement->id ])) {
266
+                                $this->oldElementUris[ $oldElement->id ] = $this->getAllElementUris($oldElement);
267 267
                             }
268 268
                         }
269 269
                     }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
         Event::on(
275 275
             Elements::class,
276 276
             Elements::EVENT_AFTER_SAVE_ELEMENT,
277
-            function (ElementEvent $event) {
277
+            function(ElementEvent $event) {
278 278
                 Craft::debug(
279 279
                     'Elements::EVENT_AFTER_SAVE_ELEMENT',
280 280
                     __METHOD__
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         Event::on(
291 291
             Plugins::class,
292 292
             Plugins::EVENT_AFTER_LOAD_PLUGINS,
293
-            function () {
293
+            function() {
294 294
                 // Install these only after all other plugins have loaded
295 295
                 $request = Craft::$app->getRequest();
296 296
                 // Only respond to non-console site requests
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         Event::on(
315 315
             UrlManager::class,
316 316
             UrlManager::EVENT_REGISTER_SITE_URL_RULES,
317
-            function (RegisterUrlRulesEvent $event) {
317
+            function(RegisterUrlRulesEvent $event) {
318 318
                 Craft::debug(
319 319
                     'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
320 320
                     __METHOD__
@@ -337,15 +337,15 @@  discard block
 block discarded – undo
337 337
         Event::on(
338 338
             Dashboard::class,
339 339
             Dashboard::EVENT_REGISTER_WIDGET_TYPES,
340
-            function (RegisterComponentTypesEvent $event) {
341
-                $event->types[] = RetourWidget::class;
340
+            function(RegisterComponentTypesEvent $event) {
341
+                $event->types[ ] = RetourWidget::class;
342 342
             }
343 343
         );
344 344
         // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES
345 345
         Event::on(
346 346
             UrlManager::class,
347 347
             UrlManager::EVENT_REGISTER_CP_URL_RULES,
348
-            function (RegisterUrlRulesEvent $event) {
348
+            function(RegisterUrlRulesEvent $event) {
349 349
                 Craft::debug(
350 350
                     'UrlManager::EVENT_REGISTER_CP_URL_RULES',
351 351
                     __METHOD__
@@ -361,20 +361,20 @@  discard block
 block discarded – undo
361 361
         Event::on(
362 362
             UserPermissions::class,
363 363
             UserPermissions::EVENT_REGISTER_PERMISSIONS,
364
-            function (RegisterUserPermissionsEvent $event) {
364
+            function(RegisterUserPermissionsEvent $event) {
365 365
                 Craft::debug(
366 366
                     'UserPermissions::EVENT_REGISTER_PERMISSIONS',
367 367
                     __METHOD__
368 368
                 );
369 369
                 // Register our custom permissions
370
-                $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions();
370
+                $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions();
371 371
             }
372 372
         );
373 373
         // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS
374 374
         Event::on(
375 375
             ClearCaches::class,
376 376
             ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
377
-            function (RegisterCacheOptionsEvent $event) {
377
+            function(RegisterCacheOptionsEvent $event) {
378 378
                 Craft::debug(
379 379
                     'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS',
380 380
                     __METHOD__
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
         Event::on(
400 400
             ErrorHandler::class,
401 401
             ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
402
-            function (ExceptionEvent $event) {
402
+            function(ExceptionEvent $event) {
403 403
                 Craft::debug(
404 404
                     'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION',
405 405
                     __METHOD__
@@ -441,15 +441,15 @@  discard block
 block discarded – undo
441 441
     protected function handleElementUriChange(Element $element)
442 442
     {
443 443
         $uris = $this->getAllElementUris($element);
444
-        $oldElementUris = $this->oldElementUris[$element->id];
444
+        $oldElementUris = $this->oldElementUris[ $element->id ];
445 445
         foreach ($uris as $siteId => $newUri) {
446
-            if (!empty($oldElementUris[$siteId])) {
447
-                $oldUri = $oldElementUris[$siteId];
446
+            if (!empty($oldElementUris[ $siteId ])) {
447
+                $oldUri = $oldElementUris[ $siteId ];
448 448
                 Craft::debug(
449 449
                     Craft::t(
450 450
                         'retour',
451 451
                         'Comparing old: {oldUri} to new: {newUri}',
452
-                        ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)]
452
+                        [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ]
453 453
                     ),
454 454
                     __METHOD__
455 455
                 );
@@ -476,12 +476,12 @@  discard block
 block discarded – undo
476 476
      */
477 477
     protected function getAllElementUris(Element $element): array
478 478
     {
479
-        $uris = [];
479
+        $uris = [ ];
480 480
         $sites = Craft::$app->getSites()->getAllSites();
481 481
         foreach ($sites as $site) {
482 482
             $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id);
483 483
             if ($uri !== null) {
484
-                $uris[$site->id] = $uri;
484
+                $uris[ $site->id ] = $uri;
485 485
             }
486 486
         }
487 487
 
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
             Craft::t(
490 490
                 'retour',
491 491
                 'Getting Element URIs: {uris}',
492
-                ['uris' => print_r($uris, true)]
492
+                [ 'uris' => print_r($uris, true) ]
493 493
             ),
494 494
             __METHOD__
495 495
         );
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
             [
556 556
                 'key' => 'retour-redirect-caches',
557 557
                 'label' => Craft::t('retour', 'Retour redirect caches'),
558
-                'action' => [self::$plugin->redirects, 'invalidateCaches'],
558
+                'action' => [ self::$plugin->redirects, 'invalidateCaches' ],
559 559
             ],
560 560
         ];
561 561
     }
Please login to merge, or discard this patch.
src/services/Redirects.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
                 Craft::t(
86 86
                     'retour',
87 87
                     '404 URL: {url}',
88
-                    ['url' => $url]
88
+                    [ 'url' => $url ]
89 89
                 ),
90 90
                 __METHOD__
91 91
             );
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
     {
115 115
         $response = Craft::$app->getResponse();
116 116
         if ($redirect !== null) {
117
-            $dest = $redirect['redirectDestUrl'];
118
-            $status = $redirect['redirectHttpCode'];
117
+            $dest = $redirect[ 'redirectDestUrl' ];
118
+            $status = $redirect[ 'redirectHttpCode' ];
119 119
             Craft::info(
120 120
                 Craft::t(
121 121
                     'retour',
122 122
                     'Redirecting {url} to {dest} with status {status}',
123
-                    ['url' => $url, 'dest' => $dest, 'status' => $status]
123
+                    [ 'url' => $url, 'dest' => $dest, 'status' => $status ]
124 124
                 ),
125 125
                 __METHOD__
126 126
             );
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
     public function getRedirectFromCache($url)
173 173
     {
174 174
         $cache = Craft::$app->getCache();
175
-        $cacheKey = $this::CACHE_KEY.md5($url);
175
+        $cacheKey = $this::CACHE_KEY . md5($url);
176 176
         $redirect = $cache->get($cacheKey);
177 177
         Craft::info(
178 178
             Craft::t(
179 179
                 'retour',
180 180
                 'Cached redirect hit for {url}',
181
-                ['url' => $url]
181
+                [ 'url' => $url ]
182 182
             ),
183 183
             __METHOD__
184 184
         );
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public function saveRedirectToCache($url, $redirect)
194 194
     {
195
-        $cacheKey = $this::CACHE_KEY.md5($url);
195
+        $cacheKey = $this::CACHE_KEY . md5($url);
196 196
         $cache = Craft::$app->getCache();
197 197
         // Get the current site id
198 198
         $sites = Craft::$app->getSites();
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $dependency = new TagDependency([
206 206
             'tags' => [
207 207
                 $this::GLOBAL_REDIRECTS_CACHE_TAG,
208
-                $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId,
208
+                $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId,
209 209
             ],
210 210
         ]);
211 211
         $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency);
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             Craft::t(
214 214
                 'retour',
215 215
                 'Cached redirect saved for {url}',
216
-                ['url' => $url]
216
+                [ 'url' => $url ]
217 217
             ),
218 218
             __METHOD__
219 219
         );
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
     {
230 230
         $result = null;
231 231
         foreach ($redirects as $redirect) {
232
-            $redirectMatchType = $redirect['redirectMatchType'] ?? null;
232
+            $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? null;
233 233
             switch ($redirectMatchType) {
234 234
                 // Do a straight up match
235 235
                 case 'exactmatch':
236
-                    if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) {
236
+                    if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) {
237 237
                         $this->incrementRedirectHitCount($redirect);
238 238
                         $this->saveRedirectToCache($url, $redirect);
239 239
 
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 
244 244
                 // Do a regex match
245 245
                 case 'regexmatch':
246
-                    $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i';
246
+                    $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i';
247 247
                     if (preg_match($matchRegEx, $url) === 1) {
248 248
                         $this->incrementRedirectHitCount($redirect);
249 249
                         // If we're not associated with an EntryID, handle capture group replacement
250
-                        if ((int)$redirect['associatedElementId'] === 0) {
251
-                            $redirect['redirectDestUrl'] = preg_replace(
250
+                        if ((int) $redirect[ 'associatedElementId' ] === 0) {
251
+                            $redirect[ 'redirectDestUrl' ] = preg_replace(
252 252
                                 $matchRegEx,
253
-                                $redirect['redirectDestUrl'],
253
+                                $redirect[ 'redirectDestUrl' ],
254 254
                                 $url
255 255
                             );
256 256
                         }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
                                 'redirect' => &$redirect,
270 270
                             ],
271 271
                         ];
272
-                        $result = \call_user_func_array([$plugin, 'retourMatch'], $args);
272
+                        $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args);
273 273
                         if ($result) {
274 274
                             $this->incrementRedirectHitCount($redirect);
275 275
                             $this->saveRedirectToCache($url, $redirect);
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
             Craft::t(
285 285
                 'retour',
286 286
                 'Not handled: {url}',
287
-                ['url' => $url]
287
+                [ 'url' => $url ]
288 288
             ),
289 289
             __METHOD__
290 290
         );
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
         foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) {
309 309
             /** @var Plugin $plugin */
310 310
             if (method_exists($plugin, 'retourMatch')) {
311
-                $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match');
311
+                $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match');
312 312
             }
313 313
         }
314 314
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
         }
329 329
         // Query the db table
330 330
         $query = (new Query())
331
-            ->from(['{{%retour_static_redirects}}'])
331
+            ->from([ '{{%retour_static_redirects}}' ])
332 332
             ->orderBy('redirectMatchType ASC, hitCount DESC');
333 333
         if ($limit) {
334 334
             $query->limit($limit);
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
     {
352 352
         // Query the db table
353 353
         $redirect = (new Query())
354
-            ->from(['{{%retour_static_redirects}}'])
355
-            ->where(['id' => $id])
354
+            ->from([ '{{%retour_static_redirects}}' ])
355
+            ->where([ 'id' => $id ])
356 356
             ->one();
357 357
 
358 358
         return $redirect;
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
     {
370 370
         // Query the db table
371 371
         $redirect = (new Query())
372
-            ->from(['{{%retour_static_redirects}}'])
373
-            ->where(['redirectSrcUrl' => $redirectSrcUrl])
372
+            ->from([ '{{%retour_static_redirects}}' ])
373
+            ->where([ 'redirectSrcUrl' => $redirectSrcUrl ])
374 374
             ->one();
375 375
 
376 376
         return $redirect;
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
     public function incrementRedirectHitCount($redirectConfig)
411 411
     {
412 412
         if ($redirectConfig !== null) {
413
-            $redirectConfig['hitCount']++;
414
-            $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime());
413
+            $redirectConfig[ 'hitCount' ]++;
414
+            $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime());
415 415
             $this->saveRedirect($redirectConfig);
416 416
         }
417 417
     }
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
                 Craft::t(
429 429
                     'retour',
430 430
                     'Error validating redirect {id}: {errors}',
431
-                    ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)]
431
+                    [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ]
432 432
                 ),
433 433
                 __METHOD__
434 434
             );
@@ -439,23 +439,23 @@  discard block
 block discarded – undo
439 439
         $redirectConfig = $redirect->getAttributes();
440 440
         $db = Craft::$app->getDb();
441 441
         // See if a redirect exists with this source URL already
442
-        if ((int)$redirectConfig['id'] === 0) {
442
+        if ((int) $redirectConfig[ 'id' ] === 0) {
443 443
             // Query the db table
444 444
             $redirect = (new Query())
445
-                ->from(['{{%retour_static_redirects}}'])
446
-                ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']])
445
+                ->from([ '{{%retour_static_redirects}}' ])
446
+                ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ])
447 447
                 ->one();
448 448
             // If it exists, update it rather than having duplicates
449 449
             if (!empty($redirect)) {
450
-                $redirectConfig['id'] = $redirect['id'];
450
+                $redirectConfig[ 'id' ] = $redirect[ 'id' ];
451 451
             }
452 452
         }
453
-        if ((int)$redirectConfig['id'] !== 0) {
453
+        if ((int) $redirectConfig[ 'id' ] !== 0) {
454 454
             Craft::debug(
455 455
                 Craft::t(
456 456
                     'retour',
457 457
                     'Updating existing redirect: {redirect}',
458
-                    ['redirect' => print_r($redirectConfig, true)]
458
+                    [ 'redirect' => print_r($redirectConfig, true) ]
459 459
                 ),
460 460
                 __METHOD__
461 461
             );
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
                     '{{%retour_static_redirects}}',
466 466
                     $redirectConfig,
467 467
                     [
468
-                        'id' => $redirectConfig['id'],
468
+                        'id' => $redirectConfig[ 'id' ],
469 469
                     ]
470 470
                 )->execute();
471 471
             } catch (Exception $e) {
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
                 Craft::t(
477 477
                     'retour',
478 478
                     'Creating new redirect: {redirect}',
479
-                    ['redirect' => print_r($redirectConfig, true)]
479
+                    [ 'redirect' => print_r($redirectConfig, true) ]
480 480
                 ),
481 481
                 __METHOD__
482 482
             );
@@ -491,13 +491,13 @@  discard block
 block discarded – undo
491 491
             }
492 492
         }
493 493
         // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl
494
-        $testRedirectConfig = $this->getRedirectByRedirectSrcUrl($redirectConfig['redirectDestUrl']);
494
+        $testRedirectConfig = $this->getRedirectByRedirectSrcUrl($redirectConfig[ 'redirectDestUrl' ]);
495 495
         if ($testRedirectConfig !== null) {
496 496
             Craft::debug(
497 497
                 Craft::t(
498 498
                     'retour',
499 499
                     'Deleting redirect to prevent a loop: {redirect}',
500
-                    ['redirect' => print_r($testRedirectConfig, true)]
500
+                    [ 'redirect' => print_r($testRedirectConfig, true) ]
501 501
                 ),
502 502
                 __METHOD__
503 503
             );
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
             try {
506 506
                 $db->createCommand()->delete(
507 507
                     '{{%retour_static_redirects}}',
508
-                    ['id' => $testRedirectConfig['id']]
508
+                    [ 'id' => $testRedirectConfig[ 'id' ] ]
509 509
                 )->execute();
510 510
             } catch (Exception $e) {
511 511
                 Craft::error($e->getMessage(), __METHOD__);
Please login to merge, or discard this patch.