Conditions | 5 |
Paths | 1 |
Total Lines | 74 |
Code Lines | 51 |
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 |
||
11 | public function change() |
||
12 | { |
||
13 | //creates permissions table |
||
14 | $table = $this->table(Configure::read('Permission.tableNameMap.permissions') ?: 'permissions'); |
||
15 | $table->addColumn('name', 'string', [ |
||
16 | 'default' => null, |
||
17 | 'limit' => 255, |
||
18 | 'null' => false, |
||
19 | ]); |
||
20 | $table->addColumn('slug', 'text', [ |
||
21 | 'default' => null, |
||
22 | 'null' => false, |
||
23 | ]); |
||
24 | $table->addColumn('created', 'datetime', [ |
||
25 | 'default' => null, |
||
26 | 'null' => false, |
||
27 | ]); |
||
28 | $table->addColumn('modified', 'datetime', [ |
||
29 | 'default' => null, |
||
30 | 'null' => false, |
||
31 | ]); |
||
32 | $table->create(); |
||
33 | |||
34 | //creates roles table |
||
35 | $table = $this->table(Configure::read('Permission.tableNameMap.roles') ?: 'roles'); |
||
36 | $table->addColumn('name', 'string', [ |
||
37 | 'default' => null, |
||
38 | 'limit' => 255, |
||
39 | 'null' => false, |
||
40 | ]); |
||
41 | $table->addColumn('slug', 'text', [ |
||
42 | 'default' => null, |
||
43 | 'null' => false, |
||
44 | ]); |
||
45 | $table->addColumn('created', 'datetime', [ |
||
46 | 'default' => null, |
||
47 | 'null' => false, |
||
48 | ]); |
||
49 | $table->addColumn('modified', 'datetime', [ |
||
50 | 'default' => null, |
||
51 | 'null' => false, |
||
52 | ]); |
||
53 | $table->create(); |
||
54 | |||
55 | //creates user_roles table |
||
56 | $table = $this->table(Configure::read('Permission.tableNameMap.users_roles') ?: 'users_roles', [ |
||
57 | 'id' => false |
||
58 | ]); |
||
59 | $table->addColumn('user_id', 'integer', [ |
||
60 | 'default' => null, |
||
61 | 'null' => false, |
||
62 | ]); |
||
63 | $table->addColumn('role_id', 'integer', [ |
||
64 | 'default' => null, |
||
65 | 'null' => false, |
||
66 | ]); |
||
67 | $table->addPrimaryKey(['user_id', 'role_id']); |
||
68 | $table->create(); |
||
69 | |||
70 | //creates roles_permissions table |
||
71 | $table = $this->table(Configure::read('Permission.tableNameMap.roles_permissions') ?: 'roles_permissions', [ |
||
72 | 'id' => false |
||
73 | ]); |
||
74 | $table->addColumn('role_id', 'integer', [ |
||
75 | 'default' => null, |
||
76 | 'null' => false, |
||
77 | ]); |
||
78 | $table->addColumn('permission_id', 'integer', [ |
||
79 | 'default' => null, |
||
80 | 'null' => false, |
||
81 | ]); |
||
82 | $table->addPrimaryKey(['role_id', 'permission_id']); |
||
83 | $table->create(); |
||
84 | } |
||
85 | } |