| Conditions | 1 |
| Paths | 1 |
| Total Lines | 86 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| 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 | Schema::create('roles', function (Blueprint $table) { |
||
| 17 | $table->engine = "InnoDB COMMENT='角色表'"; |
||
| 18 | $table->increments('id'); |
||
| 19 | |||
| 20 | $table->string('name') |
||
| 21 | ->unique() |
||
| 22 | ->comment('名称'); |
||
| 23 | |||
| 24 | $table->string('display_name') |
||
| 25 | ->comment('显示名'); |
||
| 26 | |||
| 27 | $table->string('description') |
||
| 28 | ->nullable() |
||
| 29 | ->comment('备注'); |
||
| 30 | |||
| 31 | $table->timestamps(); |
||
| 32 | }); |
||
| 33 | |||
| 34 | // Create table for associating roles to users (Many-to-Many) |
||
| 35 | Schema::create('role_user', function (Blueprint $table) { |
||
| 36 | $table->engine = "InnoDB COMMENT='角色与用户对应表'"; |
||
| 37 | $table->integer(config('admin.user_foreign_key')) |
||
| 38 | ->unsigned() |
||
| 39 | ->comment('管理员ID'); |
||
| 40 | |||
| 41 | $table->integer('role_id') |
||
| 42 | ->unsigned() |
||
| 43 | ->comment('角色ID'); |
||
| 44 | |||
| 45 | $table->primary([config('admin.user_foreign_key'), 'role_id']); |
||
| 46 | }); |
||
| 47 | |||
| 48 | // Create table for storing permissions |
||
| 49 | Schema::create('permissions', function (Blueprint $table) { |
||
| 50 | $table->engine = "InnoDB COMMENT='权限(即菜单)表'"; |
||
| 51 | |||
| 52 | $table->increments('id') |
||
| 53 | ->comment('主键'); |
||
| 54 | |||
| 55 | $table->integer('pid') |
||
| 56 | ->comment('父ID'); |
||
| 57 | |||
| 58 | $table->string('icon', 100) |
||
| 59 | ->comment('图标class') |
||
| 60 | ->default(''); |
||
| 61 | |||
| 62 | $table->string('display_name', 200) |
||
| 63 | ->comment('显示名称'); |
||
| 64 | |||
| 65 | $table->string('name', 100) |
||
| 66 | ->comment('名称'); |
||
| 67 | |||
| 68 | $table->tinyInteger('is_menu') |
||
| 69 | ->comment('是否作为菜单') |
||
| 70 | ->default('1'); |
||
| 71 | |||
| 72 | $table->tinyInteger('sort') |
||
| 73 | ->unsigned() |
||
| 74 | ->comment('排序') |
||
| 75 | ->default('0'); |
||
| 76 | |||
| 77 | $table->string('description') |
||
| 78 | ->nullable() |
||
| 79 | ->comment('描述'); |
||
| 80 | |||
| 81 | $table->timestamps(); |
||
| 82 | $table->index('pid'); |
||
| 83 | }); |
||
| 84 | |||
| 85 | // Create table for associating permissions to roles (Many-to-Many) |
||
| 86 | Schema::create('permission_role', function (Blueprint $table) { |
||
| 87 | $table->engine = "InnoDB COMMENT='权限与角色对应表'"; |
||
| 88 | $table->integer('permission_id') |
||
| 89 | ->unsigned() |
||
| 90 | ->comment('权限ID'); |
||
| 91 | |||
| 92 | $table->integer('role_id') |
||
| 93 | ->unsigned() |
||
| 94 | ->comment('角色ID'); |
||
| 95 | |||
| 96 | $table->primary(['permission_id', 'role_id']); |
||
| 97 | }); |
||
| 98 | } |
||
| 99 | |||
| 113 |
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.