Passed
Push — develop ( 23cbea...ae6640 )
by Andrew
04:12
created
src/controllers/FileController.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     // Protected Properties
74 74
     // =========================================================================
75 75
 
76
-    protected $allowAnonymous = [];
76
+    protected $allowAnonymous = [ ];
77 77
 
78 78
     // Public Methods
79 79
     // =========================================================================
@@ -98,20 +98,20 @@  discard block
 block discarded – undo
98 98
         $headers = array_flip($csv->fetchOne(0));
99 99
         $csv->setOffset(1);
100 100
         $columns = ArrayHelper::filterEmptyStringsFromArray($columns);
101
-        $csv->each(function ($row) use ($headers, $columns) {
101
+        $csv->each(function($row) use ($headers, $columns) {
102 102
             $redirectConfig = [
103 103
                 'id' => 0,
104 104
             ];
105 105
             $index = 0;
106 106
             foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) {
107
-                if (isset($columns[$index], $headers[$columns[$index]])) {
108
-                    $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]])
107
+                if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) {
108
+                    $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ])
109 109
                         ? null
110
-                        : $row[$headers[$columns[$index]]];
110
+                        : $row[ $headers[ $columns[ $index ] ] ];
111 111
                 }
112 112
                 $index++;
113 113
             }
114
-            Craft::debug('Importing row: '.print_r($redirectConfig, true), __METHOD__);
114
+            Craft::debug('Importing row: ' . print_r($redirectConfig, true), __METHOD__);
115 115
             Retour::$plugin->redirects->saveRedirect($redirectConfig);
116 116
 
117 117
             return true;
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      */
134 134
     public function actionImportCsv(string $siteHandle = null): Response
135 135
     {
136
-        $variables = [];
136
+        $variables = [ ];
137 137
         PermissionHelper::controllerPermissionCheck('retour:redirects');
138 138
         // If your CSV document was created or is read on a Macintosh computer,
139 139
         // add the following lines before using the library to help PHP detect line ending in Mac OS X
@@ -151,20 +151,20 @@  discard block
 block discarded – undo
151 151
         } catch (InvalidConfigException $e) {
152 152
             Craft::error($e->getMessage(), __METHOD__);
153 153
         }
154
-        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
154
+        $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl(
155 155
             '@nystudio107/retour/assetbundles/retour/dist',
156 156
             true
157 157
         );
158 158
         // Enabled sites
159 159
         MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
160
-        $variables['controllerHandle'] = 'file';
160
+        $variables[ 'controllerHandle' ] = 'file';
161 161
 
162 162
         // Basic variables
163
-        $variables['fullPageForm'] = true;
164
-        $variables['docsUrl'] = self::DOCUMENTATION_URL;
165
-        $variables['pluginName'] = $pluginName;
166
-        $variables['title'] = $templateTitle;
167
-        $variables['crumbs'] = [
163
+        $variables[ 'fullPageForm' ] = true;
164
+        $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL;
165
+        $variables[ 'pluginName' ] = $pluginName;
166
+        $variables[ 'title' ] = $templateTitle;
167
+        $variables[ 'crumbs' ] = [
168 168
             [
169 169
                 'label' => $pluginName,
170 170
                 'url' => UrlHelper::cpUrl('retour'),
@@ -174,19 +174,19 @@  discard block
 block discarded – undo
174 174
                 'url' => UrlHelper::cpUrl('retour/redirects'),
175 175
             ],
176 176
         ];
177
-        $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}";
178
-        $variables['selectedSubnavItem'] = 'redirects';
177
+        $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}";
178
+        $variables[ 'selectedSubnavItem' ] = 'redirects';
179 179
 
180 180
         // The CSV file
181 181
         $file = UploadedFile::getInstanceByName('file');
182 182
         if ($file !== null) {
183
-            $filename = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.uniqid($file->name, true);
183
+            $filename = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . uniqid($file->name, true);
184 184
             $file->saveAs($filename, false);
185 185
             $csv = Reader::createFromPath($file->tempName);
186 186
             $headers = $csv->fetchOne(0);
187 187
             Craft::info(print_r($headers, true), __METHOD__);
188
-            $variables['headers'] = $headers;
189
-            $variables['filename'] = $filename;
188
+            $variables[ 'headers' ] = $headers;
189
+            $variables[ 'filename' ] = $filename;
190 190
         }
191 191
 
192 192
         // Render the template
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
         }
233 233
         // Query the db table
234 234
         $data = (new Query())
235
-            ->from([$table])
235
+            ->from([ $table ])
236 236
             ->select(array_keys($columns))
237 237
             ->orderBy('hitCount DESC')
238 238
             ->all();
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
         $csv = Writer::createFromFileObject(new \SplTempFileObject());
241 241
         $csv->insertOne(array_values($columns));
242 242
         $csv->insertAll($data);
243
-        $csv->output($filename.'.csv');
243
+        $csv->output($filename . '.csv');
244 244
         exit(0);
245 245
     }
246 246
 }
Please login to merge, or discard this patch.