| Conditions | 3 |
| Paths | 3 |
| Total Lines | 73 |
| Code Lines | 61 |
| 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 | $defaults = [ |
||
| 28 | 1 => [ |
||
| 29 | 1 => 1, |
||
| 30 | 2 => 1, |
||
| 31 | 3 => 1, |
||
| 32 | 4 => 1, |
||
| 33 | 5 => 1, |
||
| 34 | 6 => 1, |
||
| 35 | 7 => 1, |
||
| 36 | 8 => 1, |
||
| 37 | 9 => 1, |
||
| 38 | 10 => 1, |
||
| 39 | ], |
||
| 40 | 2 => [ |
||
| 41 | 1 => 1, |
||
| 42 | 2 => 1, |
||
| 43 | 3 => 1, |
||
| 44 | 4 => 1, |
||
| 45 | 5 => 1, |
||
| 46 | 6 => 1, |
||
| 47 | 7 => 1, |
||
| 48 | 8 => 1, |
||
| 49 | 9 => 0, |
||
| 50 | 10 => 0, |
||
| 51 | ], |
||
| 52 | 3 => [ |
||
| 53 | 1 => 0, |
||
| 54 | 2 => 1, |
||
| 55 | 3 => 1, |
||
| 56 | 4 => 0, |
||
| 57 | 5 => 1, |
||
| 58 | 6 => 1, |
||
| 59 | 7 => 0, |
||
| 60 | 8 => 0, |
||
| 61 | 9 => 0, |
||
| 62 | 10 => 0, |
||
| 63 | ], |
||
| 64 | 4 => [ |
||
| 65 | 1 => 0, |
||
| 66 | 2 => 0, |
||
| 67 | 3 => 1, |
||
| 68 | 4 => 0, |
||
| 69 | 5 => 1, |
||
| 70 | 6 => 1, |
||
| 71 | 7 => 0, |
||
| 72 | 8 => 0, |
||
| 73 | 9 => 0, |
||
| 74 | 10 => 0, |
||
| 75 | ], |
||
| 76 | ]; |
||
| 77 | |||
| 78 | foreach($defaults as $role_id => $perms) |
||
| 79 | { |
||
| 80 | foreach($perms as $perm_type_id => $allow) |
||
| 81 | { |
||
| 82 | DB::table('user_role_permissions')->insert([ |
||
| 83 | 'role_id' => $role_id, |
||
| 84 | 'perm_type_id' => $perm_type_id, |
||
| 85 | 'allow' => $allow, |
||
| 86 | 'created_at' => Carbon::now(), |
||
| 87 | 'updated_at' => Carbon::now(), |
||
| 88 | ]); |
||
| 103 |