Conditions | 3 |
Paths | 2 |
Total Lines | 77 |
Code Lines | 53 |
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 | if (empty($tableNames)) { |
||
20 | throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding.'); |
||
21 | } |
||
22 | |||
23 | Schema::create($tableNames['permissions'], function (Blueprint $table) { |
||
24 | $table->bigIncrements('id'); |
||
25 | $table->uuid('uuid')->default('-'); |
||
26 | $table->string('name'); |
||
27 | $table->string('guard_name'); |
||
28 | $table->timestamps(); |
||
29 | }); |
||
30 | |||
31 | Schema::create($tableNames['roles'], function (Blueprint $table) { |
||
32 | $table->bigIncrements('id'); |
||
33 | $table->uuid('uuid')->default('-'); |
||
34 | $table->string('name'); |
||
35 | $table->string('guard_name'); |
||
36 | $table->timestamps(); |
||
37 | }); |
||
38 | |||
39 | Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) { |
||
40 | $table->unsignedBigInteger('permission_id'); |
||
41 | |||
42 | $table->string('model_type'); |
||
43 | $table->unsignedBigInteger($columnNames['model_morph_key']); |
||
44 | $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); |
||
45 | |||
46 | $table->foreign('permission_id') |
||
47 | ->references('id') |
||
48 | ->on($tableNames['permissions']) |
||
49 | ->onDelete('cascade'); |
||
50 | |||
51 | $table->primary(['permission_id', $columnNames['model_morph_key'], 'model_type'], |
||
52 | 'model_has_permissions_permission_model_type_primary'); |
||
53 | }); |
||
54 | |||
55 | Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) { |
||
56 | $table->unsignedBigInteger('role_id'); |
||
57 | |||
58 | $table->string('model_type'); |
||
59 | $table->unsignedBigInteger($columnNames['model_morph_key']); |
||
60 | $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); |
||
61 | |||
62 | $table->foreign('role_id') |
||
63 | ->references('id') |
||
64 | ->on($tableNames['roles']) |
||
65 | ->onDelete('cascade'); |
||
66 | |||
67 | $table->primary(['role_id', $columnNames['model_morph_key'], 'model_type'], |
||
68 | 'model_has_roles_role_model_type_primary'); |
||
69 | }); |
||
70 | |||
71 | Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { |
||
72 | $table->unsignedBigInteger('permission_id'); |
||
73 | $table->unsignedBigInteger('role_id'); |
||
74 | |||
75 | $table->foreign('permission_id') |
||
76 | ->references('id') |
||
77 | ->on($tableNames['permissions']) |
||
78 | ->onDelete('cascade'); |
||
79 | |||
80 | $table->foreign('role_id') |
||
81 | ->references('id') |
||
82 | ->on($tableNames['roles']) |
||
83 | ->onDelete('cascade'); |
||
84 | |||
85 | $table->primary(['permission_id', 'role_id'], 'role_has_permissions_permission_id_role_id_primary'); |
||
86 | }); |
||
87 | |||
88 | app('cache') |
||
89 | ->store('default' != config('permission.cache.store') ? config('permission.cache.store') : null) |
||
90 | ->forget(config('permission.cache.key')); |
||
91 | } |
||
113 |