Conditions | 1 |
Paths | 1 |
Total Lines | 122 |
Code Lines | 69 |
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 |
||
10 | public function up() |
||
11 | { |
||
12 | $roles = [ |
||
13 | [ |
||
14 | 'id' => 1, |
||
15 | 'name' => 'system' |
||
16 | ], |
||
17 | [ |
||
18 | 'id' => 2, |
||
19 | 'name' => 'admin' |
||
20 | ], |
||
21 | [ |
||
22 | 'id' => 3, |
||
23 | 'name' => 'member' |
||
24 | ], |
||
25 | [ |
||
26 | 'id' => 4, |
||
27 | 'name' => 'guest' |
||
28 | ], |
||
29 | ]; |
||
30 | $this->table('acl_roles')->insert($roles)->save(); |
||
31 | |||
32 | $privileges = [ |
||
33 | [ |
||
34 | 'roleId' => 2, |
||
35 | 'module' => 'acl', |
||
36 | 'privilege' => 'Management' |
||
37 | ], |
||
38 | [ |
||
39 | 'roleId' => 2, |
||
40 | 'module' => 'acl', |
||
41 | 'privilege' => 'View' |
||
42 | ], |
||
43 | [ |
||
44 | 'roleId' => 2, |
||
45 | 'module' => 'api', |
||
46 | 'privilege' => 'Users/Id' |
||
47 | ], |
||
48 | [ |
||
49 | 'roleId' => 2, |
||
50 | 'module' => 'api', |
||
51 | 'privilege' => 'Users/Profile' |
||
52 | ], |
||
53 | [ |
||
54 | 'roleId' => 2, |
||
55 | 'module' => 'cache', |
||
56 | 'privilege' => 'Management' |
||
57 | ], |
||
58 | [ |
||
59 | 'roleId' => 2, |
||
60 | 'module' => 'dashboard', |
||
61 | 'privilege' => 'Dashboard' |
||
62 | ], |
||
63 | [ |
||
64 | 'roleId' => 2, |
||
65 | 'module' => 'pages', |
||
66 | 'privilege' => 'Management' |
||
67 | ], |
||
68 | [ |
||
69 | 'roleId' => 2, |
||
70 | 'module' => 'system', |
||
71 | 'privilege' => 'Info' |
||
72 | ], |
||
73 | [ |
||
74 | 'roleId' => 2, |
||
75 | 'module' => 'users', |
||
76 | 'privilege' => 'EditEmail' |
||
77 | ], |
||
78 | [ |
||
79 | 'roleId' => 2, |
||
80 | 'module' => 'users', |
||
81 | 'privilege' => 'EditPassword' |
||
82 | ], |
||
83 | [ |
||
84 | 'roleId' => 2, |
||
85 | 'module' => 'users', |
||
86 | 'privilege' => 'Management' |
||
87 | ], |
||
88 | [ |
||
89 | 'roleId' => 2, |
||
90 | 'module' => 'users', |
||
91 | 'privilege' => 'ViewProfile' |
||
92 | ], |
||
93 | [ |
||
94 | 'roleId' => 3, |
||
95 | 'module' => 'api', |
||
96 | 'privilege' => 'Users/Profile' |
||
97 | ], |
||
98 | [ |
||
99 | 'roleId' => 3, |
||
100 | 'module' => 'users', |
||
101 | 'privilege' => 'EditEmail' |
||
102 | ], |
||
103 | [ |
||
104 | 'roleId' => 3, |
||
105 | 'module' => 'users', |
||
106 | 'privilege' => 'EditPassword' |
||
107 | ], |
||
108 | [ |
||
109 | 'roleId' => 3, |
||
110 | 'module' => 'users', |
||
111 | 'privilege' => 'ViewProfile' |
||
112 | ], |
||
113 | ]; |
||
114 | $this->table('acl_privileges')->insert($privileges)->save(); |
||
115 | |||
116 | $usersRoles = [ |
||
117 | [ |
||
118 | 'userId' => 1, |
||
119 | 'roleId' => 1 |
||
120 | ], |
||
121 | [ |
||
122 | 'userId' => 2, |
||
123 | 'roleId' => 2 |
||
124 | ], |
||
125 | [ |
||
126 | 'userId' => 3, |
||
127 | 'roleId' => 3 |
||
128 | ], |
||
129 | ]; |
||
130 | $this->table('acl_users_roles')->insert($usersRoles)->save(); |
||
131 | } |
||
132 | |||
143 |
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.