| Conditions | 3 |
| Paths | 3 |
| Total Lines | 77 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 15 | public function up() |
||
| 16 | { |
||
| 17 | Schema::create('user_role_permissions', function(Blueprint $table) { |
||
| 18 | $table->increments('id'); |
||
| 19 | $table->integer('role_id')->unsigned(); |
||
| 20 | $table->integer('perm_type_id')->unsigned(); |
||
| 21 | $table->boolean('allow')->default(0); |
||
| 22 | $table->timestamps(); |
||
| 23 | $table->foreign('role_id')->references('role_id')->on('user_role_types')->onUpdate('cascade'); |
||
| 24 | $table->foreign('perm_type_id')->references('perm_type_id')->on('user_role_permission_types')->onUpdate('cascade'); |
||
| 25 | }); |
||
| 26 | |||
| 27 | // Setup the default role permissions |
||
| 28 | $defaults = [ |
||
| 29 | 1 => [ |
||
| 30 | 1 => 1, |
||
| 31 | 2 => 1, |
||
| 32 | 3 => 1, |
||
| 33 | 4 => 1, |
||
| 34 | 5 => 1, |
||
| 35 | 6 => 1, |
||
| 36 | 7 => 1, |
||
| 37 | 8 => 1, |
||
| 38 | 9 => 1, |
||
| 39 | 10 => 1, |
||
| 40 | 11 => 1, |
||
| 41 | ], |
||
| 42 | 2 => [ |
||
| 43 | 1 => 1, |
||
| 44 | 2 => 1, |
||
| 45 | 3 => 1, |
||
| 46 | 4 => 1, |
||
| 47 | 5 => 1, |
||
| 48 | 6 => 1, |
||
| 49 | 7 => 1, |
||
| 50 | 8 => 1, |
||
| 51 | 9 => 1, |
||
| 52 | 10 => 1, |
||
| 53 | 11 => 1, |
||
| 54 | ], |
||
| 55 | 3 => [ |
||
| 56 | 1 => 0, |
||
| 57 | 2 => 0, |
||
| 58 | 3 => 1, |
||
| 59 | 4 => 1, |
||
| 60 | 5 => 0, |
||
| 61 | 6 => 0, |
||
| 62 | 7 => 1, |
||
| 63 | 8 => 1, |
||
| 64 | 9 => 0, |
||
| 65 | 10 => 0, |
||
| 66 | 11 => 0, |
||
| 67 | ], |
||
| 68 | 4 => [ |
||
| 69 | 1 => 0, |
||
| 70 | 2 => 0, |
||
| 71 | 3 => 0, |
||
| 72 | 4 => 1, |
||
| 73 | 5 => 0, |
||
| 74 | 6 => 0, |
||
| 75 | 7 => 1, |
||
| 76 | 8 => 1, |
||
| 77 | 9 => 0, |
||
| 78 | 10 => 0, |
||
| 79 | 11 => 0, |
||
| 80 | ], |
||
| 81 | ]; |
||
| 82 | |||
| 83 | foreach($defaults as $role_id => $perms) |
||
| 84 | { |
||
| 85 | foreach($perms as $perm_type_id => $allow) |
||
| 86 | { |
||
| 87 | DB::table('user_role_permissions')->insert([ |
||
| 88 | 'role_id' => $role_id, |
||
| 89 | 'perm_type_id' => $perm_type_id, |
||
| 90 | 'allow' => $allow, |
||
| 91 | 'created_at' => Carbon::now(), |
||
| 92 | 'updated_at' => Carbon::now(), |
||
| 108 |