Conditions | 2 |
Paths | 2 |
Total Lines | 108 |
Code Lines | 72 |
Lines | 17 |
Ratio | 15.74 % |
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 |
||
26 | public function up() |
||
27 | { |
||
28 | // Create table for admin user |
||
29 | if ($this->managerTable != 'users') { |
||
30 | View Code Duplication | Schema::create($this->managerTable, function (Blueprint $table) { |
|
31 | $table->engine = "InnoDB COMMENT='管理员表'"; |
||
32 | $table->increments('id'); |
||
33 | |||
34 | $table->string('name') |
||
35 | ->unique() |
||
36 | ->comment('名称'); |
||
37 | |||
38 | $table->string('email') |
||
39 | ->nullable() |
||
40 | ->unique() |
||
41 | ->comment('邮箱'); |
||
42 | |||
43 | $table->string('password') |
||
44 | ->nullable() |
||
45 | ->comment('密码'); |
||
46 | |||
47 | $table->rememberToken(); |
||
48 | $table->timestamps(); |
||
49 | }); |
||
50 | } |
||
51 | |||
52 | // Create table for storing roles |
||
53 | View Code Duplication | Schema::create('roles', function (Blueprint $table) { |
|
54 | $table->engine = "InnoDB COMMENT='角色表'"; |
||
55 | $table->increments('id'); |
||
56 | |||
57 | $table->string('name') |
||
58 | ->unique() |
||
59 | ->comment('名称'); |
||
60 | |||
61 | $table->string('display_name') |
||
62 | ->nullable() |
||
63 | ->comment('显示名'); |
||
64 | |||
65 | $table->string('description') |
||
66 | ->nullable() |
||
67 | ->comment('备注'); |
||
68 | |||
69 | $table->timestamps(); |
||
70 | }); |
||
71 | |||
72 | // Create table for associating roles to users (Many-to-Many) |
||
73 | Schema::create('role_user', function (Blueprint $table) { |
||
74 | $table->engine = "InnoDB COMMENT='角色与用户对应表'"; |
||
75 | $table->integer($this->managerForeignKey) |
||
76 | ->unsigned() |
||
77 | ->comment('管理员ID'); |
||
78 | $table->integer('role_id') |
||
79 | ->unsigned() |
||
80 | ->comment('角色ID'); |
||
81 | |||
82 | $table->primary([$this->managerForeignKey, 'role_id']); |
||
83 | }); |
||
84 | |||
85 | // Create table for storing permissions |
||
86 | Schema::create('permissions', function (Blueprint $table) { |
||
87 | $table->engine = "InnoDB COMMENT='权限(即菜单)表'"; |
||
88 | $table->increments('id')->comment('主键'); |
||
89 | |||
90 | $table->integer('pid') |
||
91 | ->comment('父ID'); |
||
92 | |||
93 | $table->string('icon', 100) |
||
94 | ->comment('图标class') |
||
95 | ->default(''); |
||
96 | |||
97 | $table->string('display_name', 200) |
||
98 | ->comment('显示名称'); |
||
99 | |||
100 | $table->string('name', 100) |
||
101 | ->comment('名称'); |
||
102 | |||
103 | $table->tinyInteger('is_menu') |
||
104 | ->comment('是否作为菜单') |
||
105 | ->default('1'); |
||
106 | |||
107 | $table->tinyInteger('sort') |
||
108 | ->unsigned() |
||
109 | ->comment('排序') |
||
110 | ->default('0'); |
||
111 | |||
112 | $table->string('description') |
||
113 | ->nullable() |
||
114 | ->comment('描述'); |
||
115 | |||
116 | $table->timestamps(); |
||
117 | $table->index('pid'); |
||
118 | }); |
||
119 | |||
120 | // Create table for associating permissions to roles (Many-to-Many) |
||
121 | Schema::create('permission_role', function (Blueprint $table) { |
||
122 | $table->engine = "InnoDB COMMENT='权限与角色对应表'"; |
||
123 | $table->integer('permission_id') |
||
124 | ->unsigned() |
||
125 | ->comment('权限ID'); |
||
126 | |||
127 | $table->integer('role_id') |
||
128 | ->unsigned() |
||
129 | ->comment('角色ID'); |
||
130 | |||
131 | $table->primary(['permission_id', 'role_id']); |
||
132 | }); |
||
133 | } |
||
134 | |||
151 |
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.