Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 3195c5...0b5ddf )
by Cristian
02:56
created
src/Crud.php 3 patches
Doc Comments   +21 added lines, -4 removed lines patch added patch discarded remove patch
@@ -334,6 +334,7 @@  discard block
 block discarded – undo
334 334
      * Delete a row from the database.
335 335
      *
336 336
      * @param  [int] The id of the item to be deleted.
337
+     * @param integer $id
337 338
      * @return [bool] Deletion confirmation.
338 339
      *
339 340
      * TODO: should this delete items with relations to it too?
@@ -452,7 +453,8 @@  discard block
 block discarded – undo
452 453
      * Check if a permission is enabled for a Crud Panel. Fail if not.
453 454
      *
454 455
      * @param  [string] Permission.
455
-     * @return boolean
456
+     * @param string $permission
457
+     * @return boolean|null
456 458
      */
457 459
     public function hasAccessOrFail($permission)
458 460
     {
@@ -481,6 +483,7 @@  discard block
 block discarded – undo
481 483
      * All Create-Read-Update-Delete operations are done using that Eloquent Collection.
482 484
      *
483 485
      * @param [string] Full model namespace. Ex: App\Models\Article
486
+     * @param string $model_namespace
484 487
      */
485 488
     public function setModel($model_namespace)
486 489
     {
@@ -508,6 +511,7 @@  discard block
 block discarded – undo
508 511
      *
509 512
      * @param [string] Route name.
510 513
      * @param [array] Parameters.
514
+     * @param string $route
511 515
      */
512 516
     public function setRoute($route)
513 517
     {
@@ -540,7 +544,7 @@  discard block
 block discarded – undo
540 544
      * - $this->crud->setRouteName('admin.article')
541 545
      * - $this->crud->route = "admin/article"
542 546
      *
543
-     * @return [string]
547
+     * @return string
544 548
      */
545 549
     public function getRoute()
546 550
     {
@@ -553,6 +557,8 @@  discard block
 block discarded – undo
553 557
      *
554 558
      * @param [string] Entity name, in singular. Ex: article
555 559
      * @param [string] Entity name, in plural. Ex: articles
560
+     * @param string $singular
561
+     * @param string $plural
556 562
      */
557 563
     public function setEntityNameStrings($singular, $plural) {
558 564
         $this->entity_name = $singular;
@@ -731,8 +737,6 @@  discard block
 block discarded – undo
731 737
 
732 738
     /**
733 739
      * Add a field to the create/update form or both.
734
-     * @param [string] $name    Field name (the column name in the db in most cases)
735
-     * @param [array] $options Field-type-specific information.
736 740
      * @param string $form    The form to add the field to (create/update/both)
737 741
      */
738 742
     public function addField($field, $form='both')
@@ -1374,6 +1378,9 @@  discard block
 block discarded – undo
1374 1378
     //     return array_filter($this->{$entity}[] = $this->syncField($field));
1375 1379
     // }
1376 1380
 
1381
+    /**
1382
+     * @param string $entity
1383
+     */
1377 1384
     public function addMultiple($entity, $field)
1378 1385
     {
1379 1386
         $this->{$entity} = array_filter(array_map([$this, 'syncField'], $fields));
@@ -1398,11 +1405,17 @@  discard block
 block discarded – undo
1398 1405
     //     return array_values(array_filter($this->{$entity}, function($field) use ($fields) { return !in_array($field['name'], (array)$fields);}));
1399 1406
     // }
1400 1407
 
1408
+    /**
1409
+     * @param string $items
1410
+     */
1401 1411
     public function setSort($items, $order)
1402 1412
     {
1403 1413
         $this->sort[$items] = $order;
1404 1414
     }
1405 1415
 
1416
+    /**
1417
+     * @param string $items
1418
+     */
1406 1419
     public function sort($items)
1407 1420
     {
1408 1421
         if (array_key_exists($items, $this->sort))
@@ -1438,6 +1451,10 @@  discard block
 block discarded – undo
1438 1451
     }
1439 1452
 
1440 1453
     // face un fel de merge intre ce ii dai si ce e in CRUD
1454
+
1455
+    /**
1456
+     * @param string $entity
1457
+     */
1441 1458
     public function syncRelations($entity)
1442 1459
     {
1443 1460
         foreach ($this->relations as $field => $relation) {
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 
102 102
         $relationFields = [];
103 103
 
104
-        foreach($fields as $field){
105
-            if(isset($field['model']) || isset($field['dependencies'])){
104
+        foreach ($fields as $field) {
105
+            if (isset($field['model']) || isset($field['dependencies'])) {
106 106
                 array_push($relationFields, $field);
107 107
             }
108 108
         }
@@ -118,22 +118,22 @@  discard block
 block discarded – undo
118 118
 
119 119
         foreach ($relations as $key => $relation)
120 120
         {
121
-            if ( (isset($relation['pivot']) && $relation['pivot'] ) || isset($relation['dependencies']) ){
122
-                if(is_array($relation['name'])){
123
-                    foreach($relation['name'] as $relation){
124
-                        if(isset($data[$relation])){
121
+            if ((isset($relation['pivot']) && $relation['pivot']) || isset($relation['dependencies'])) {
122
+                if (is_array($relation['name'])) {
123
+                    foreach ($relation['name'] as $relation) {
124
+                        if (isset($data[$relation])) {
125 125
                             $model->{$relation}()->sync($data[$relation]);
126
-                        }else{
126
+                        } else {
127 127
                              $model->{$relation}()->sync([]);
128 128
                         }
129 129
                     }
130
-                }else{
130
+                } else {
131 131
                     $model->{$relation['name']}()->sync($data[$relation['name']]);
132 132
                 }
133 133
 
134
-                if( isset($relation['pivotFields']) ){
135
-                    foreach($relation['pivotFields'] as $pivotField){
136
-                       foreach($data[$pivotField] as $pivot_id =>  $field){
134
+                if (isset($relation['pivotFields'])) {
135
+                    foreach ($relation['pivotFields'] as $pivotField) {
136
+                       foreach ($data[$pivotField] as $pivot_id =>  $field) {
137 137
                          $model->{$relation['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]);
138 138
                        }
139 139
                     }
@@ -298,14 +298,14 @@  discard block
 block discarded – undo
298 298
             // set the value
299 299
             if (!isset($fields[$k]['value']))
300 300
             {
301
-                if(is_array($field['name'])){
301
+                if (is_array($field['name'])) {
302 302
 
303 303
                     $fields[$k]['value'] = [];
304
-                    foreach($field['name'] as  $key => $relation){
304
+                    foreach ($field['name'] as  $key => $relation) {
305 305
                         $fields[$k]['value'][] = $entry->{$relation};
306 306
                     }
307 307
 
308
-                }else{
308
+                } else {
309 309
                     $fields[$k]['value'] = $entry->{$field['name']};
310 310
                 }
311 311
             }
@@ -424,13 +424,13 @@  discard block
 block discarded – undo
424 424
     public function allowAccess($access)
425 425
     {
426 426
         // $this->addButtons((array)$access);
427
-        return $this->access = array_merge(array_diff((array)$access, $this->access), $this->access);
427
+        return $this->access = array_merge(array_diff((array) $access, $this->access), $this->access);
428 428
     }
429 429
 
430 430
     public function denyAccess($access)
431 431
     {
432 432
         // $this->removeButtons((array)$access);
433
-        return $this->access = array_diff($this->access, (array)$access);
433
+        return $this->access = array_diff($this->access, (array) $access);
434 434
     }
435 435
 
436 436
     /**
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
      */
644 644
     public function addDefaultTypeToColumn($column)
645 645
     {
646
-        if (array_key_exists('name', (array)$column))
646
+        if (array_key_exists('name', (array) $column))
647 647
         {
648 648
             $default_type = $this->getFieldTypeFromDbColumnType($column['name']);
649 649
             return array_merge(['type' => $default_type], $column);
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
      * @param [field or column]
660 660
      */
661 661
     public function addDefaultLabel($array) {
662
-        if (!array_key_exists('label', (array)$array) && array_key_exists('name', (array)$array)) {
662
+        if (!array_key_exists('label', (array) $array) && array_key_exists('name', (array) $array)) {
663 663
             $array = array_merge(['label' => ucfirst($this->makeLabel($array['name']))], $array);
664 664
             return $array;
665 665
         }
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
      * @param [array] $options Field-type-specific information.
736 736
      * @param string $form    The form to add the field to (create/update/both)
737 737
      */
738
-    public function addField($field, $form='both')
738
+    public function addField($field, $form = 'both')
739 739
     {
740 740
         // if the field_defition_array array is a string, it means the programmer was lazy and has only passed the name
741 741
         // set some default values, so the field will still work
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
      * @param  string $name Field name (as defined with the addField() procedure)
779 779
      * @param  string $form update/create/both
780 780
      */
781
-    public function removeField($name, $form='both')
781
+    public function removeField($name, $form = 'both')
782 782
     {
783 783
         switch (strtolower($form)) {
784 784
             case 'create':
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
      * @param  array $array_of_names A simple array of the names of the fields to be removed.
802 802
      * @param  string $form          update/create/both
803 803
      */
804
-    public function removeFields($array_of_names, $form='both')
804
+    public function removeFields($array_of_names, $form = 'both')
805 805
     {
806 806
         if (!empty($array_of_names)) {
807 807
             foreach ($array_of_names as $name) {
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
         array_map(function($field) {
923 923
             // $this->labels[$field] = $this->makeLabel($field);
924 924
 
925
-            $new_field =  [
925
+            $new_field = [
926 926
                                 'name' => $field,
927 927
                                 'label' => ucfirst($field),
928 928
                                 'value' => '', 'default' => $this->field_types[$field]['default'],
@@ -1263,7 +1263,7 @@  discard block
 block discarded – undo
1263 1263
 
1264 1264
     public function orderColumns($order)
1265 1265
     {
1266
-        $this->setSort('columns', (array)$order);
1266
+        $this->setSort('columns', (array) $order);
1267 1267
     }
1268 1268
 
1269 1269
 
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
 
1339 1339
     public function orderFields($order)
1340 1340
     {
1341
-        $this->setSort('fields', (array)$order);
1341
+        $this->setSort('fields', (array) $order);
1342 1342
     }
1343 1343
 
1344 1344
 
@@ -1384,7 +1384,7 @@  discard block
 block discarded – undo
1384 1384
         if (!empty($this->{$type}))
1385 1385
         {
1386 1386
             $this->{$type} = array_map(function($field) use ($fields, $attributes) {
1387
-                if (in_array($field['name'], (array)$fields)) $field = array_merge($field, $attributes);
1387
+                if (in_array($field['name'], (array) $fields)) $field = array_merge($field, $attributes);
1388 1388
 
1389 1389
                 return $field;
1390 1390
             }, $this->{$type});
@@ -1414,7 +1414,7 @@  discard block
 block discarded – undo
1414 1414
                 if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) $elements[] = $this->{$items}[$key];
1415 1415
             }
1416 1416
 
1417
-            return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]);}));
1417
+            return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]); }));
1418 1418
         }
1419 1419
 
1420 1420
         return $this->{$items};
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
     // cred ca ia valorile din tabela de legatura ca sa ti le afiseze in select
1428 1428
     public function getRelationValues($model, $field, $where = [], $order = [])
1429 1429
     {
1430
-        $order = (array)$order;
1430
+        $order = (array) $order;
1431 1431
         $values = $model->select('*');
1432 1432
 
1433 1433
         if (!empty($where)) call_user_func_array([$values, $where[0]], array_slice($where, 1));
Please login to merge, or discard this patch.
Braces   +52 added lines, -27 removed lines patch added patch discarded remove patch
@@ -93,8 +93,7 @@  discard block
 block discarded – undo
93 93
         if ($form == 'create')
94 94
         {
95 95
             $fields = $this->create_fields;
96
-        }
97
-        else
96
+        } else
98 97
         {
99 98
             $fields = $this->update_fields;
100 99
         }
@@ -123,11 +122,11 @@  discard block
 block discarded – undo
123 122
                     foreach($relation['name'] as $relation){
124 123
                         if(isset($data[$relation])){
125 124
                             $model->{$relation}()->sync($data[$relation]);
126
-                        }else{
125
+                        } else{
127 126
                              $model->{$relation}()->sync([]);
128 127
                         }
129 128
                     }
130
-                }else{
129
+                } else{
131 130
                     $model->{$relation['name']}()->sync($data[$relation['name']]);
132 131
                 }
133 132
 
@@ -305,7 +304,7 @@  discard block
 block discarded – undo
305 304
                         $fields[$k]['value'][] = $entry->{$relation};
306 305
                     }
307 306
 
308
-                }else{
307
+                } else{
309 308
                     $fields[$k]['value'] = $entry->{$field['name']};
310 309
                 }
311 310
             }
@@ -484,7 +483,9 @@  discard block
 block discarded – undo
484 483
      */
485 484
     public function setModel($model_namespace)
486 485
     {
487
-        if (!class_exists($model_namespace)) throw new \Exception('This model does not exist.', 404);
486
+        if (!class_exists($model_namespace)) {
487
+            throw new \Exception('This model does not exist.', 404);
488
+        }
488 489
 
489 490
         $this->model = new $model_namespace();
490 491
         $this->query = $this->model->select('*');
@@ -526,7 +527,9 @@  discard block
 block discarded – undo
526 527
     {
527 528
         $complete_route = $route.'.index';
528 529
 
529
-        if (!\Route::has($complete_route)) throw new \Exception('There are no routes for this route name.', 404);
530
+        if (!\Route::has($complete_route)) {
531
+            throw new \Exception('There are no routes for this route name.', 404);
532
+        }
530 533
 
531 534
         $this->route = route($complete_route, $parameters);
532 535
         $this->initButtons();
@@ -582,8 +585,7 @@  discard block
 block discarded – undo
582 585
                 // if label and other details have been defined in the array
583 586
                 if (is_array($columns[0])) {
584 587
                     $this->addColumn($column);
585
-                }
586
-                else
588
+                } else
587 589
                 {
588 590
                     $this->addColumn([
589 591
                                     'name' => $column,
@@ -742,19 +744,20 @@  discard block
 block discarded – undo
742 744
         if (is_string($field))
743 745
         {
744 746
             $complete_field_array['name'] = $field;
745
-        }
746
-        else
747
+        } else
747 748
         {
748 749
             $complete_field_array = $field;
749 750
         }
750 751
 
751 752
         // if the label is missing, we should set it
752
-        if (!isset($complete_field_array['label']))
753
-            $complete_field_array['label'] = ucfirst($complete_field_array['name']);
753
+        if (!isset($complete_field_array['label'])) {
754
+                    $complete_field_array['label'] = ucfirst($complete_field_array['name']);
755
+        }
754 756
 
755 757
         // if the field type is missing, we should set it
756
-        if (!isset($complete_field_array['type']))
757
-            $complete_field_array['type'] = $this->getFieldTypeFromDbColumnType($complete_field_array['name']);
758
+        if (!isset($complete_field_array['type'])) {
759
+                    $complete_field_array['type'] = $this->getFieldTypeFromDbColumnType($complete_field_array['name']);
760
+        }
758 761
 
759 762
         // store the field information into the correct variable on the CRUD object
760 763
         switch (strtolower($form)) {
@@ -970,11 +973,17 @@  discard block
 block discarded – undo
970 973
      */
971 974
     public function getFieldTypeFromDbColumnType($field)
972 975
     {
973
-        if (!array_key_exists($field, $this->field_types)) return 'text';
976
+        if (!array_key_exists($field, $this->field_types)) {
977
+            return 'text';
978
+        }
974 979
 
975
-        if ($field == 'password') return 'password';
980
+        if ($field == 'password') {
981
+            return 'password';
982
+        }
976 983
 
977
-        if ($field == 'email') return 'email';
984
+        if ($field == 'email') {
985
+            return 'email';
986
+        }
978 987
 
979 988
         switch ($this->field_types[$field]['type'])
980 989
         {
@@ -1047,7 +1056,9 @@  discard block
 block discarded – undo
1047 1056
         $columns = \Schema::getColumnListing($this->model->getTable());
1048 1057
         $fillable = $this->model->getFillable();
1049 1058
 
1050
-        if (!empty($fillable)) $columns = array_intersect($columns, $fillable);
1059
+        if (!empty($fillable)) {
1060
+            $columns = array_intersect($columns, $fillable);
1061
+        }
1051 1062
 
1052 1063
         // but not updated_at, deleted_at
1053 1064
         return array_values(array_diff($columns, [$this->model->getKeyName(), 'updated_at', 'deleted_at']));
@@ -1363,8 +1374,11 @@  discard block
 block discarded – undo
1363 1374
 
1364 1375
             foreach ($this->{$fields} as $key => $field)
1365 1376
             {
1366
-                if (array_key_exists($field['name'], $this->relations) && $this->relations[$field['name']]['pivot']) $this->{$fields}[$key]['value'] = $this->entry->{$this->relations[$field['name']]['name']}()->lists($this->relations[$field['name']]['model']->getKeyName())->toArray();
1367
-                    else $this->{$fields}[$key]['value'] = $this->entry->{$field['name']};
1377
+                if (array_key_exists($field['name'], $this->relations) && $this->relations[$field['name']]['pivot']) {
1378
+                    $this->{$fields}[$key]['value'] = $this->entry->{$this->relations[$field['name']]['name']}()->lists($this->relations[$field['name']]['model']->getKeyName())->toArray();
1379
+                } else {
1380
+                        $this->{$fields}[$key]['value'] = $this->entry->{$field['name']};
1381
+                    }
1368 1382
             }
1369 1383
         }
1370 1384
     }
@@ -1384,7 +1398,9 @@  discard block
 block discarded – undo
1384 1398
         if (!empty($this->{$type}))
1385 1399
         {
1386 1400
             $this->{$type} = array_map(function($field) use ($fields, $attributes) {
1387
-                if (in_array($field['name'], (array)$fields)) $field = array_merge($field, $attributes);
1401
+                if (in_array($field['name'], (array)$fields)) {
1402
+                    $field = array_merge($field, $attributes);
1403
+                }
1388 1404
 
1389 1405
                 return $field;
1390 1406
             }, $this->{$type});
@@ -1411,7 +1427,9 @@  discard block
 block discarded – undo
1411 1427
 
1412 1428
             foreach ($this->sort[$items] as $item)
1413 1429
             {
1414
-                if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) $elements[] = $this->{$items}[$key];
1430
+                if (is_numeric($key = array_search($item, array_column($this->{$items}, 'name')))) {
1431
+                    $elements[] = $this->{$items}[$key];
1432
+                }
1415 1433
             }
1416 1434
 
1417 1435
             return $this->{$items} = array_merge($elements, array_filter($this->{$items}, function($item) use($items) {return !in_array($item['name'], $this->sort[$items]);}));
@@ -1430,9 +1448,13 @@  discard block
 block discarded – undo
1430 1448
         $order = (array)$order;
1431 1449
         $values = $model->select('*');
1432 1450
 
1433
-        if (!empty($where)) call_user_func_array([$values, $where[0]], array_slice($where, 1));
1451
+        if (!empty($where)) {
1452
+            call_user_func_array([$values, $where[0]], array_slice($where, 1));
1453
+        }
1434 1454
 
1435
-        if (!empty($order)) call_user_func_array([$values, 'orderBy'], $order);
1455
+        if (!empty($order)) {
1456
+            call_user_func_array([$values, 'orderBy'], $order);
1457
+        }
1436 1458
 
1437 1459
         return $values->get()->lists($field, $model->getKeyName())->toArray();
1438 1460
     }
@@ -1441,8 +1463,11 @@  discard block
 block discarded – undo
1441 1463
     public function syncRelations($entity)
1442 1464
     {
1443 1465
         foreach ($this->relations as $field => $relation) {
1444
-            if ($relation['pivot']) $this->add($entity, ['name' => $field, 'type' => 'multiselect', 'value' => [], 'values' => $this->relations[$field]['values']]);
1445
-                else $this->sync($entity, $field, ['type' => 'select', 'values' => $this->relations[$field]['values']]);
1466
+            if ($relation['pivot']) {
1467
+                $this->add($entity, ['name' => $field, 'type' => 'multiselect', 'value' => [], 'values' => $this->relations[$field]['values']]);
1468
+            } else {
1469
+                    $this->sync($entity, $field, ['type' => 'select', 'values' => $this->relations[$field]['values']]);
1470
+                }
1446 1471
         }
1447 1472
     }
1448 1473
 
Please login to merge, or discard this patch.