We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Lines | 22 |
Ratio | 36.07 % |
Changes | 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 |
||
13 | public function up() |
||
14 | { |
||
15 | $tableNames = config('permission.table_names'); |
||
16 | |||
17 | Schema::create($tableNames['permissions'], function (Blueprint $table) { |
||
18 | $table->increments('id'); |
||
19 | $table->string('name'); |
||
20 | $table->string('guard_name'); |
||
21 | $table->timestamps(); |
||
22 | }); |
||
23 | |||
24 | Schema::create($tableNames['roles'], function (Blueprint $table) { |
||
25 | $table->increments('id'); |
||
26 | $table->string('name'); |
||
27 | $table->string('guard_name'); |
||
28 | $table->timestamps(); |
||
29 | }); |
||
30 | |||
31 | View Code Duplication | Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames) { |
|
32 | $table->integer('permission_id')->unsigned(); |
||
33 | $table->morphs('model'); |
||
34 | |||
35 | $table->foreign('permission_id') |
||
36 | ->references('id') |
||
37 | ->on($tableNames['permissions']) |
||
38 | ->onDelete('cascade'); |
||
39 | |||
40 | $table->primary(['permission_id', 'model_id', 'model_type']); |
||
41 | }); |
||
42 | |||
43 | View Code Duplication | Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames) { |
|
44 | $table->integer('role_id')->unsigned(); |
||
45 | $table->morphs('model'); |
||
46 | |||
47 | $table->foreign('role_id') |
||
48 | ->references('id') |
||
49 | ->on($tableNames['roles']) |
||
50 | ->onDelete('cascade'); |
||
51 | |||
52 | $table->primary(['role_id', 'model_id', 'model_type']); |
||
53 | }); |
||
54 | |||
55 | Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { |
||
56 | $table->integer('permission_id')->unsigned(); |
||
57 | $table->integer('role_id')->unsigned(); |
||
58 | |||
59 | $table->foreign('permission_id') |
||
60 | ->references('id') |
||
61 | ->on($tableNames['permissions']) |
||
62 | ->onDelete('cascade'); |
||
63 | |||
64 | $table->foreign('role_id') |
||
65 | ->references('id') |
||
66 | ->on($tableNames['roles']) |
||
67 | ->onDelete('cascade'); |
||
68 | |||
69 | $table->primary(['permission_id', 'role_id']); |
||
70 | |||
71 | Cache::forget('spatie.permission.cache'); |
||
72 | }); |
||
73 | } |
||
74 | |||
91 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.