Completed
Push — master ( a15e69...5fe226 )
by Adrian
15:41 queued 11:35
created
src/Abstractor/Eloquent/Model.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,6 @@
 block discarded – undo
16 16
 use Anavel\Crud\Abstractor\Exceptions\AbstractorException;
17 17
 use Illuminate\Http\Request;
18 18
 use Illuminate\Support\Collection;
19
-use League\Flysystem\Adapter\Local;
20
-use League\Flysystem\Filesystem;
21 19
 
22 20
 class Model implements ModelAbstractorContract
23 21
 {
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
         }
144 144
 
145 145
         $customDisplayedColumns = $this->getConfigValue($action, 'display');
146
-        $customHiddenColumns = $this->getConfigValue($action, 'hide') ? : [];
146
+        $customHiddenColumns = $this->getConfigValue($action, 'hide') ?: [];
147 147
 
148 148
         $columns = array();
149
-        if (! empty($customDisplayedColumns) && is_array($customDisplayedColumns)) {
149
+        if (!empty($customDisplayedColumns) && is_array($customDisplayedColumns)) {
150 150
             foreach ($customDisplayedColumns as $customColumn) {
151 151
                 if (strpos($customColumn, '.')) {
152 152
                     $customColumnRelation = explode('.', $customColumn);
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
 
162 162
                     $relationColumns = $nestedRelation->getModelAbstractor()->getColumns($action);
163 163
 
164
-                    if (! array_key_exists($customColumnRelationFieldName, $relationColumns)) {
165
-                        throw new AbstractorException("Column " . $customColumnRelationFieldName . " does not exist on relation " . implode('.', $customColumnRelation) . " of model " . $this->getModel());
164
+                    if (!array_key_exists($customColumnRelationFieldName, $relationColumns)) {
165
+                        throw new AbstractorException("Column ".$customColumnRelationFieldName." does not exist on relation ".implode('.', $customColumnRelation)." of model ".$this->getModel());
166 166
                     }
167 167
 
168 168
                     $columns[$customColumn] = $relationColumns[$customColumnRelationFieldName];
169 169
                 } else {
170
-                    if (! array_key_exists($customColumn, $tableColumns)) {
171
-                        throw new AbstractorException("Column " . $customColumn . " does not exist on " . $this->getModel());
170
+                    if (!array_key_exists($customColumn, $tableColumns)) {
171
+                        throw new AbstractorException("Column ".$customColumn." does not exist on ".$this->getModel());
172 172
                     }
173 173
 
174 174
                     $columns[$customColumn] = $tableColumns[$customColumn];
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
     {
196 196
         $relations = $modelAbstractor->getRelations();
197 197
 
198
-        if (! $relations->has($relationName)) {
199
-            throw new AbstractorException("Relation " . $relationName . " not configured on " . $modelAbstractor->getModel());
198
+        if (!$relations->has($relationName)) {
199
+            throw new AbstractorException("Relation ".$relationName." not configured on ".$modelAbstractor->getModel());
200 200
         }
201 201
 
202 202
         $relation = $relations->get($relationName);
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 
218 218
         $relations = collect();
219 219
 
220
-        if (! empty($configRelations)) {
220
+        if (!empty($configRelations)) {
221 221
             foreach ($configRelations as $relationName => $configRelation) {
222 222
                 if (is_int($relationName)) {
223 223
                     $relationName = $configRelation;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 
226 226
                 $config = [];
227 227
                 if ($configRelation !== $relationName) {
228
-                    if (! is_array($configRelation)) {
228
+                    if (!is_array($configRelation)) {
229 229
                         $config['type'] = $configRelation;
230 230
                     } else {
231 231
                         $config = $configRelation;
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
                 $secondaryRelations = $relation->getSecondaryRelations();
241 241
 
242 242
 
243
-                if (! $secondaryRelations->isEmpty()) {
243
+                if (!$secondaryRelations->isEmpty()) {
244 244
                     $relations->put(
245 245
                         $relationName,
246 246
                         collect(['relation' => $relation, 'secondaryRelations' => $secondaryRelations])
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
     {
264 264
         $columns = $this->getColumns('list');
265 265
 
266
-        $fieldsPresentation = $this->getConfigValue('fields_presentation') ? : [];
266
+        $fieldsPresentation = $this->getConfigValue('fields_presentation') ?: [];
267 267
 
268 268
         $fields = array();
269 269
         foreach ($columns as $name => $column) {
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     {
299 299
         $columns = $this->getColumns('detail');
300 300
 
301
-        $fieldsPresentation = $this->getConfigValue('fields_presentation') ? : [];
301
+        $fieldsPresentation = $this->getConfigValue('fields_presentation') ?: [];
302 302
 
303 303
         $fields = array();
304 304
         foreach ($columns as $name => $column) {
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 
339 339
         $fields = array();
340 340
         foreach ($columns as $name => $column) {
341
-            if (! in_array($name, $this->getReadOnlyColumns())) {
341
+            if (!in_array($name, $this->getReadOnlyColumns())) {
342 342
                 $presentation = null;
343 343
                 if (array_key_exists($name, $this->fieldsPresentation)) {
344 344
                     $presentation = $this->fieldsPresentation[$name];
@@ -359,24 +359,24 @@  discard block
 block discarded – undo
359 359
                     ->setConfig($config)
360 360
                     ->get();
361 361
 
362
-                if (! empty($this->instance) && ! empty($this->instance->getAttribute($name))) {
362
+                if (!empty($this->instance) && !empty($this->instance->getAttribute($name))) {
363 363
                     $field->setValue($this->instance->getAttribute($name));
364 364
                 }
365 365
 
366 366
                 $fields[$arrayKey][$name] = $field;
367 367
 
368
-                if (! empty($config['form_type']) && $config['form_type'] === 'file') {
368
+                if (!empty($config['form_type']) && $config['form_type'] === 'file') {
369 369
                     $field = $this->fieldFactory
370 370
                         ->setColumn($column)
371 371
                         ->setConfig([
372
-                            'name'         => $name . '__delete',
372
+                            'name'         => $name.'__delete',
373 373
                             'presentation' => null,
374 374
                             'form_type'    => 'checkbox',
375 375
                             'no_validate'  => true,
376 376
                             'functions'    => null
377 377
                         ])
378 378
                         ->get();
379
-                    $fields[$arrayKey][$name . '__delete'] = $field;
379
+                    $fields[$arrayKey][$name.'__delete'] = $field;
380 380
                 }
381 381
             }
382 382
         }
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
     {
414 414
         /** @var \ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager $modelManager */
415 415
         $modelManager = App::make('ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager');
416
-        if (! empty($this->instance)) {
416
+        if (!empty($this->instance)) {
417 417
             $item = $this->instance;
418 418
         } else {
419 419
             $item = $modelManager->getModelInstance($this->getModel());
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
             return;
426 426
         }
427 427
 
428
-        if (! empty($fields['main'])) {
428
+        if (!empty($fields['main'])) {
429 429
             $skip = null;
430 430
             foreach ($fields['main'] as $key => $field) {
431 431
                 /** @var FieldContract $field */
@@ -449,21 +449,21 @@  discard block
 block discarded – undo
449 449
                 }
450 450
 
451 451
                 if (get_class($field->getFormField()) === \FormManager\Fields\File::class) {
452
-                    $handleResult = $this->handleField($request, $item, $fields['main'], 'main', $fieldName,$this->mustDeleteFilesInFilesystem);
453
-                    if (! empty($handleResult['skip'])) {
452
+                    $handleResult = $this->handleField($request, $item, $fields['main'], 'main', $fieldName, $this->mustDeleteFilesInFilesystem);
453
+                    if (!empty($handleResult['skip'])) {
454 454
                         $skip = $handleResult['skip'];
455 455
                     }
456
-                    if (! empty($handleResult['requestValue'])) {
456
+                    if (!empty($handleResult['requestValue'])) {
457 457
                         $requestValue = $handleResult['requestValue'];
458 458
                     }
459 459
                 }
460 460
 
461 461
 
462
-                if (! $field->saveIfEmpty() && empty($requestValue)) {
462
+                if (!$field->saveIfEmpty() && empty($requestValue)) {
463 463
                     continue;
464 464
                 }
465 465
 
466
-                if (! empty($requestValue) || (empty($requestValue) && ! empty($item->getAttribute($fieldName)))) {
466
+                if (!empty($requestValue) || (empty($requestValue) && !empty($item->getAttribute($fieldName)))) {
467 467
                     $item->setAttribute(
468 468
                         $fieldName,
469 469
                         $field->applyFunctions($requestValue)
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
         $this->setInstance($item);
478 478
 
479 479
 
480
-        if (! empty($relations = $this->getRelations())) {
480
+        if (!empty($relations = $this->getRelations())) {
481 481
             foreach ($relations as $relationKey => $relation) {
482 482
                 if ($relation instanceof Collection) {
483 483
                     $input = $request->input($relationKey);
Please login to merge, or discard this patch.
src/Abstractor/Eloquent/Traits/HandleFiles.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
      * @param Request $request
16 16
      * @param Model $item
17 17
      * @param array $fields
18
-     * @param $groupName
18
+     * @param string $groupName
19 19
      * @param $fieldName
20 20
      * @param bool $mustDeleteFilesInFilesystem
21 21
      * @return array
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 namespace Anavel\Crud\Abstractor\Eloquent\Traits;
5 5
 
6 6
 use Illuminate\Database\Eloquent\Model;
7
-use Illuminate\Support\Facades\App;
8 7
 use League\Flysystem\Adapter\Local;
9 8
 use League\Flysystem\Filesystem;
10 9
 use Illuminate\Http\Request;
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -21,26 +21,26 @@  discard block
 block discarded – undo
21 21
      * @return array
22 22
      * @throws \Exception
23 23
      */
24
-    protected function handleField(Request $request, $item, array $fields, $groupName, $fieldName, $mustDeleteFilesInFilesystem=false)
24
+    protected function handleField(Request $request, $item, array $fields, $groupName, $fieldName, $mustDeleteFilesInFilesystem = false)
25 25
     {
26 26
 
27 27
 
28
-        $normalizeGroupName = str_replace('.','#',$groupName);
29
-        $contentFromUploadedField="uploaded-content.{$normalizeGroupName}#{$fieldName}#";
30
-        $modelFolder = $this->slug . DIRECTORY_SEPARATOR;
31
-        $basePath = base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR .config('anavel-crud.uploads_path'));
32
-        $modelPath = $basePath . $modelFolder;
28
+        $normalizeGroupName = str_replace('.', '#', $groupName);
29
+        $contentFromUploadedField = "uploaded-content.{$normalizeGroupName}#{$fieldName}#";
30
+        $modelFolder = $this->slug.DIRECTORY_SEPARATOR;
31
+        $basePath = base_path(DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.config('anavel-crud.uploads_path'));
32
+        $modelPath = $basePath.$modelFolder;
33 33
         $skip = null;
34 34
         $requestValue = null;
35 35
 
36 36
 
37
-        if (! empty($fields["{$fieldName}__delete"])) {
37
+        if (!empty($fields["{$fieldName}__delete"])) {
38 38
             //We never want to save this field, it doesn't exist in the DB
39 39
             $skip = "{$fieldName}__delete";
40 40
 
41 41
 
42 42
             //If user wants to delete the existing file
43
-            if (! empty($request->input("{$groupName}.{$fieldName}__delete"))) {
43
+            if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) {
44 44
                 $adapter = new Local($basePath);
45 45
                 $filesystem = new Filesystem($adapter);
46 46
                 if ($filesystem->has($item->$fieldName) && $mustDeleteFilesInFilesystem) {
@@ -58,32 +58,32 @@  discard block
 block discarded – undo
58 58
             }
59 59
         }
60 60
 
61
-        if($request->has($contentFromUploadedField))
61
+        if ($request->has($contentFromUploadedField))
62 62
         {
63 63
             $requestValue = $request->input($contentFromUploadedField);
64 64
 
65
-        }elseif ($request->hasFile($groupName .'.'.$fieldName)) {
66
-            $fileName = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME);
67
-            $extension = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION);
65
+        }elseif ($request->hasFile($groupName.'.'.$fieldName)) {
66
+            $fileName = pathinfo($request->file($groupName.'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME);
67
+            $extension = pathinfo($request->file($groupName.'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION);
68 68
 
69
-            $fileName = uniqid() . '_' . slugify($fileName);
70
-            if (! empty($extension)) {
71
-                $fileName .= '.' . $extension;
69
+            $fileName = uniqid().'_'.slugify($fileName);
70
+            if (!empty($extension)) {
71
+                $fileName .= '.'.$extension;
72 72
             }
73 73
 
74 74
 
75
-            $request->file($groupName .'.'.$fieldName)->move(
75
+            $request->file($groupName.'.'.$fieldName)->move(
76 76
                 $modelPath,
77 77
                 $fileName
78 78
             );
79 79
 
80
-            $requestValue = $modelFolder . $fileName;
81
-        } elseif (! empty($request->file($groupName .'.'.$fieldName)) && ! $request->file($groupName .'.'.$fieldName)->isValid()) {
82
-            throw new \Exception($request->file($groupName .'.'.$fieldName)->getErrorMessage());
80
+            $requestValue = $modelFolder.$fileName;
81
+        } elseif (!empty($request->file($groupName.'.'.$fieldName)) && !$request->file($groupName.'.'.$fieldName)->isValid()) {
82
+            throw new \Exception($request->file($groupName.'.'.$fieldName)->getErrorMessage());
83 83
         }
84 84
 
85 85
         //Avoid losing the existing filename if the user doesn't change it:
86
-        if (empty($requestValue) && (! empty($item->$fieldName))) {
86
+        if (empty($requestValue) && (!empty($item->$fieldName))) {
87 87
             $requestValue = $item->$fieldName;
88 88
         }
89 89
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
         {
63 63
             $requestValue = $request->input($contentFromUploadedField);
64 64
 
65
-        }elseif ($request->hasFile($groupName .'.'.$fieldName)) {
65
+        } elseif ($request->hasFile($groupName .'.'.$fieldName)) {
66 66
             $fileName = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME);
67 67
             $extension = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION);
68 68
 
Please login to merge, or discard this patch.
src/Abstractor/Eloquent/Relation/MiniCrud.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 
148 148
                 $config = [
149 149
                     'name' => $columnName,
150
-                    'presentation' => $this->name . ' ' . ucfirst(transcrud($columnName)),
150
+                    'presentation' => $this->name.' '.ucfirst(transcrud($columnName)),
151 151
                     'form_type' => $formType,
152 152
                     'no_validate' => true,
153 153
                     'validation' => null,
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
                     $field = $this->fieldFactory
169 169
                         ->setColumn($column)
170 170
                         ->setConfig([
171
-                            'name' => $columnName . '__delete',
171
+                            'name' => $columnName.'__delete',
172 172
                             'presentation' => null,
173 173
                             'form_type' => 'checkbox',
174 174
                             'no_validate' => true,
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
                             'functions' => null
177 177
                         ])
178 178
                         ->get();
179
-                    $fields[$columnName . '__delete'] = $field;
179
+                    $fields[$columnName.'__delete'] = $field;
180 180
                 }
181 181
             }
182 182
         }
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
 
222 222
                     if (get_class($field->getFormField()) === \FormManager\Fields\File::class) {
223 223
                         $handleResult = $this->handleField($request, $relationModel, $fieldsBase,
224
-                            $this->name . ".$relationIndex", $fieldName, $this->modelAbstractor->mustDeleteFilesInFilesystem());
225
-                        if (! empty($handleResult['skip'])) {
224
+                            $this->name.".$relationIndex", $fieldName, $this->modelAbstractor->mustDeleteFilesInFilesystem());
225
+                        if (!empty($handleResult['skip'])) {
226 226
                             $skip = $handleResult['skip'];
227 227
                             unset($relationArray[$relationIndex][$skip]);
228 228
                         }
229
-                        if (! empty($handleResult['requestValue'])) {
229
+                        if (!empty($handleResult['requestValue'])) {
230 230
                             $relationArray[$relationIndex][$fieldName] = $handleResult['requestValue'];
231 231
                         }
232 232
                     }
Please login to merge, or discard this patch.