| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| Code Lines | 49 |
| 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 |
||
| 14 | public function up() |
||
| 15 | { |
||
| 16 | $tableNames = config('permission.table_names'); |
||
| 17 | $columnNames = config('permission.column_names'); |
||
| 18 | |||
| 19 | Schema::create($tableNames['permissions'], function (Blueprint $table) { |
||
| 20 | $table->increments('id'); |
||
| 21 | $table->string('name'); |
||
| 22 | $table->string('guard_name'); |
||
| 23 | $table->timestamps(); |
||
| 24 | }); |
||
| 25 | |||
| 26 | Schema::create($tableNames['roles'], function (Blueprint $table) { |
||
| 27 | $table->increments('id'); |
||
| 28 | $table->string('name'); |
||
| 29 | $table->string('guard_name'); |
||
| 30 | $table->timestamps(); |
||
| 31 | }); |
||
| 32 | |||
| 33 | Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) { |
||
| 34 | $table->unsignedInteger('permission_id'); |
||
| 35 | |||
| 36 | $table->string('model_type'); |
||
| 37 | $table->unsignedBigInteger($columnNames['model_morph_key']); |
||
| 38 | $table->index([$columnNames['model_morph_key'], 'model_type']); |
||
| 39 | |||
| 40 | $table->foreign('permission_id') |
||
| 41 | ->references('id') |
||
| 42 | ->on($tableNames['permissions']) |
||
| 43 | ->onDelete('cascade'); |
||
| 44 | |||
| 45 | $table->primary( |
||
| 46 | ['permission_id', $columnNames['model_morph_key'], 'model_type'], |
||
| 47 | 'model_has_permissions_permission_model_type_primary' |
||
| 48 | ); |
||
| 49 | }); |
||
| 50 | |||
| 51 | Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) { |
||
| 52 | $table->unsignedInteger('role_id'); |
||
| 53 | |||
| 54 | $table->string('model_type'); |
||
| 55 | $table->unsignedBigInteger($columnNames['model_morph_key']); |
||
| 56 | $table->index([$columnNames['model_morph_key'], 'model_type']); |
||
| 57 | |||
| 58 | $table->foreign('role_id') |
||
| 59 | ->references('id') |
||
| 60 | ->on($tableNames['roles']) |
||
| 61 | ->onDelete('cascade'); |
||
| 62 | |||
| 63 | $table->primary( |
||
| 64 | ['role_id', $columnNames['model_morph_key'], 'model_type'], |
||
| 65 | 'model_has_roles_role_model_type_primary' |
||
| 66 | ); |
||
| 67 | }); |
||
| 68 | |||
| 69 | Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { |
||
| 70 | $table->unsignedInteger('permission_id'); |
||
| 71 | $table->unsignedInteger('role_id'); |
||
| 72 | |||
| 73 | $table->foreign('permission_id') |
||
| 74 | ->references('id') |
||
| 75 | ->on($tableNames['permissions']) |
||
| 76 | ->onDelete('cascade'); |
||
| 77 | |||
| 78 | $table->foreign('role_id') |
||
| 79 | ->references('id') |
||
| 80 | ->on($tableNames['roles']) |
||
| 81 | ->onDelete('cascade'); |
||
| 82 | |||
| 83 | $table->primary(['permission_id', 'role_id']); |
||
| 84 | |||
| 85 | app('cache')->forget('spatie.permission.cache'); |
||
| 86 | }); |
||
| 105 |