| Conditions | 2 |
| Paths | 2 |
| Total Lines | 63 |
| Code Lines | 39 |
| Lines | 17 |
| Ratio | 26.98 % |
| 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 |
||
| 25 | public function up() |
||
| 26 | { |
||
| 27 | // Create table for admin user |
||
| 28 | if ($this->userTable != 'users') { |
||
| 29 | View Code Duplication | Schema::create($this->userTable, function (Blueprint $table) { |
|
| 30 | $table->engine = "InnoDB COMMENT='管理员表'"; |
||
| 31 | $table->increments('id'); |
||
| 32 | $table->string('name')->unique()->comment('名称'); |
||
| 33 | $table->string('email')->nullable()->unique()->comment('邮箱'); |
||
| 34 | $table->string('password')->nullable()->comment('密码'); |
||
| 35 | $table->rememberToken(); |
||
| 36 | $table->timestamps(); |
||
| 37 | }); |
||
| 38 | } |
||
| 39 | |||
| 40 | // Create table for storing roles |
||
| 41 | View Code Duplication | Schema::create('roles', function (Blueprint $table) { |
|
| 42 | $table->engine = "InnoDB COMMENT='角色表'"; |
||
| 43 | $table->increments('id'); |
||
| 44 | $table->string('name')->unique()->comment('名称'); |
||
| 45 | $table->string('display_name')->nullable()->comment('显示名'); |
||
| 46 | $table->string('description')->nullable()->comment('备注'); |
||
| 47 | $table->timestamps(); |
||
| 48 | }); |
||
| 49 | |||
| 50 | // Create table for associating roles to users (Many-to-Many) |
||
| 51 | Schema::create('role_user', function (Blueprint $table) { |
||
| 52 | $table->engine = "InnoDB COMMENT='角色与用户对应表'"; |
||
| 53 | $table->integer($this->userForeignKey)->unsigned()->comment('管理员ID'); |
||
| 54 | $table->integer('role_id')->unsigned()->comment('角色ID'); |
||
| 55 | |||
| 56 | /*$table->foreign('uid')->references('id')->on('users') |
||
| 57 | ->onUpdate('cascade')->onDelete('cascade'); |
||
| 58 | $table->foreign('role_id')->references('id')->on('roles') |
||
| 59 | ->onUpdate('cascade')->onDelete('cascade');*/ |
||
| 60 | |||
| 61 | $table->primary([$this->userForeignKey, 'role_id']); |
||
| 62 | }); |
||
| 63 | |||
| 64 | // Create table for storing permissions |
||
| 65 | Schema::create('permissions', function (Blueprint $table) { |
||
| 66 | $table->engine = "InnoDB COMMENT='权限(即菜单)表'"; |
||
| 67 | $table->increments('id')->comment('主键'); |
||
| 68 | $table->integer('pid')->comment('父ID'); |
||
| 69 | $table->string('icon', 100)->comment('图标class'); |
||
| 70 | $table->string('display_name', 200)->comment('显示名称'); |
||
| 71 | $table->string('name', 100)->comment('名称'); |
||
| 72 | $table->tinyInteger('is_menu')->comment('是否作为菜单')->default('1'); |
||
| 73 | $table->tinyInteger('sort')->unsigned()->comment('排序'); |
||
| 74 | $table->string('description')->nullable()->comment('描述'); |
||
| 75 | $table->timestamps(); |
||
| 76 | $table->index('pid'); |
||
| 77 | }); |
||
| 78 | |||
| 79 | // Create table for associating permissions to roles (Many-to-Many) |
||
| 80 | Schema::create('permission_role', function (Blueprint $table) { |
||
| 81 | $table->engine = "InnoDB COMMENT='权限与角色对应表'"; |
||
| 82 | $table->integer('permission_id')->unsigned()->comment('权限ID'); |
||
| 83 | $table->integer('role_id')->unsigned()->comment('角色ID'); |
||
| 84 | |||
| 85 | $table->primary(['permission_id', 'role_id']); |
||
| 86 | }); |
||
| 87 | } |
||
| 88 | |||
| 105 |
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.