Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
12 | public function up() |
||
13 | { |
||
14 | $tableNames = config('permission.table_names'); |
||
15 | |||
16 | Schema::create($tableNames['permissions'], function (Blueprint $table) { |
||
17 | $table->increments('id'); |
||
18 | $table->string('name'); |
||
19 | $table->string('guard_name'); |
||
20 | $table->timestamps(); |
||
21 | }); |
||
22 | |||
23 | Schema::create($tableNames['roles'], function (Blueprint $table) { |
||
24 | $table->increments('id'); |
||
25 | $table->string('name'); |
||
26 | $table->string('guard_name'); |
||
27 | $table->timestamps(); |
||
28 | }); |
||
29 | |||
30 | Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames) { |
||
31 | $table->unsignedInteger('permission_id'); |
||
32 | $table->morphs('model'); |
||
33 | |||
34 | $table->foreign('permission_id') |
||
35 | ->references('id') |
||
36 | ->on($tableNames['permissions']) |
||
37 | ->onDelete('cascade'); |
||
38 | |||
39 | $table->primary(['permission_id', 'model_id', 'model_type']); |
||
40 | }); |
||
41 | |||
42 | Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames) { |
||
43 | $table->unsignedInteger('role_id'); |
||
44 | $table->morphs('model'); |
||
45 | |||
46 | $table->foreign('role_id') |
||
47 | ->references('id') |
||
48 | ->on($tableNames['roles']) |
||
49 | ->onDelete('cascade'); |
||
50 | |||
51 | $table->primary(['role_id', 'model_id', 'model_type']); |
||
52 | }); |
||
53 | |||
54 | Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { |
||
55 | $table->unsignedInteger('permission_id'); |
||
56 | $table->unsignedInteger('role_id'); |
||
57 | |||
58 | $table->foreign('permission_id') |
||
59 | ->references('id') |
||
60 | ->on($tableNames['permissions']) |
||
61 | ->onDelete('cascade'); |
||
62 | |||
63 | $table->foreign('role_id') |
||
64 | ->references('id') |
||
65 | ->on($tableNames['roles']) |
||
66 | ->onDelete('cascade'); |
||
67 | |||
68 | $table->primary(['permission_id', 'role_id']); |
||
69 | |||
70 | app('cache')->forget('spatie.permission.cache'); |
||
71 | }); |
||
88 |