| Conditions | 2 |
| Paths | 2 |
| Total Lines | 78 |
| Code Lines | 42 |
| Lines | 11 |
| Ratio | 14.1 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 13 | public function up() |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Insert the permissions related to this module. |
||
| 17 | */ |
||
| 18 | DB::table('permissions')->insert( |
||
| 19 | [ |
||
| 20 | /** |
||
| 21 | * Reporting model permissions. |
||
| 22 | */ |
||
| 23 | [ |
||
| 24 | 'name' => 'find', |
||
| 25 | 'model' => 'reports', |
||
| 26 | 'created_at' => \DB::raw('NOW()'), |
||
| 27 | 'updated_at' => \DB::raw('NOW()') |
||
| 28 | ], |
||
| 29 | [ |
||
| 30 | 'name' => 'search', |
||
| 31 | 'model' => 'reports', |
||
| 32 | 'created_at' => \DB::raw('NOW()'), |
||
| 33 | 'updated_at' => \DB::raw('NOW()') |
||
| 34 | ], |
||
| 35 | [ |
||
| 36 | 'name' => 'list', |
||
| 37 | 'model' => 'reports', |
||
| 38 | 'created_at' => \DB::raw('NOW()'), |
||
| 39 | 'updated_at' => \DB::raw('NOW()') |
||
| 40 | ], |
||
| 41 | [ |
||
| 42 | 'name' => 'findby', |
||
| 43 | 'model' => 'reports', |
||
| 44 | 'created_at' => \DB::raw('NOW()'), |
||
| 45 | 'updated_at' => \DB::raw('NOW()') |
||
| 46 | ], |
||
| 47 | [ |
||
| 48 | 'name' => 'first', |
||
| 49 | 'model' => 'reports', |
||
| 50 | 'created_at' => \DB::raw('NOW()'), |
||
| 51 | 'updated_at' => \DB::raw('NOW()') |
||
| 52 | ], |
||
| 53 | [ |
||
| 54 | 'name' => 'paginate', |
||
| 55 | 'model' => 'reports', |
||
| 56 | 'created_at' => \DB::raw('NOW()'), |
||
| 57 | 'updated_at' => \DB::raw('NOW()') |
||
| 58 | ], |
||
| 59 | [ |
||
| 60 | 'name' => 'paginateby', |
||
| 61 | 'model' => 'reports', |
||
| 62 | 'created_at' => \DB::raw('NOW()'), |
||
| 63 | 'updated_at' => \DB::raw('NOW()') |
||
| 64 | ], |
||
| 65 | [ |
||
| 66 | 'name' => 'admin_count', |
||
| 67 | 'model' => 'reports', |
||
| 68 | 'created_at' => \DB::raw('NOW()'), |
||
| 69 | 'updated_at' => \DB::raw('NOW()') |
||
| 70 | ] |
||
| 71 | ] |
||
| 72 | ); |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Assign the permissions to the admin group. |
||
| 76 | */ |
||
| 77 | $permissionIds = DB::table('permissions')->whereIn('model', ['reports'])->select('id')->pluck('id'); |
||
| 78 | $adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
||
| 79 | View Code Duplication | foreach ($permissionIds as $permissionId) |
|
| 80 | { |
||
| 81 | DB::table('groups_permissions')->insert( |
||
| 82 | [ |
||
| 83 | 'permission_id' => $permissionId, |
||
| 84 | 'group_id' => $adminGroupId, |
||
| 85 | 'created_at' => \DB::raw('NOW()'), |
||
| 86 | 'updated_at' => \DB::raw('NOW()') |
||
| 87 | ] |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 103 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.