Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
Code Lines | 41 |
Lines | 48 |
Ratio | 82.76 % |
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 | // Create table for storing roles |
||
16 | View Code Duplication | Schema::create('roles', function (Blueprint $table) { |
|
17 | $table->increments('id'); |
||
18 | $table->string('name')->unique(); |
||
19 | $table->string('display_name')->nullable(); |
||
20 | $table->string('description')->nullable(); |
||
21 | $table->timestamps(); |
||
22 | }); |
||
23 | |||
24 | // Create table for associating roles to users (Many-to-Many) |
||
25 | View Code Duplication | Schema::create('role_user', function (Blueprint $table) { |
|
26 | $table->integer('user_id')->unsigned(); |
||
27 | $table->integer('role_id')->unsigned(); |
||
28 | |||
29 | $table->foreign('user_id') |
||
30 | ->references('id') |
||
31 | ->on('users') |
||
32 | ->onUpdate('cascade') |
||
33 | ->onDelete('cascade'); |
||
34 | $table->foreign('role_id') |
||
35 | ->references('id') |
||
36 | ->on('roles') |
||
37 | ->onUpdate('cascade') |
||
38 | ->onDelete('cascade'); |
||
39 | |||
40 | $table->primary(['user_id', 'role_id']); |
||
41 | }); |
||
42 | |||
43 | // Create table for storing permissions |
||
44 | View Code Duplication | Schema::create('permissions', function (Blueprint $table) { |
|
45 | $table->increments('id'); |
||
46 | $table->string('name')->unique(); |
||
47 | $table->string('display_name')->nullable(); |
||
48 | $table->string('description')->nullable(); |
||
49 | $table->timestamps(); |
||
50 | }); |
||
51 | |||
52 | // Create table for associating permissions to roles (Many-to-Many) |
||
53 | View Code Duplication | Schema::create('permission_role', function (Blueprint $table) { |
|
54 | $table->integer('permission_id')->unsigned(); |
||
55 | $table->integer('role_id')->unsigned(); |
||
56 | |||
57 | $table->foreign('permission_id') |
||
58 | ->references('id') |
||
59 | ->on('permissions') |
||
60 | ->onUpdate('cascade') |
||
61 | ->onDelete('cascade'); |
||
62 | $table->foreign('role_id') |
||
63 | ->references('id') |
||
64 | ->on('roles') |
||
65 | ->onUpdate('cascade') |
||
66 | ->onDelete('cascade'); |
||
67 | |||
68 | $table->primary(['permission_id', 'role_id']); |
||
69 | }); |
||
70 | } |
||
71 | |||
85 |
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.