Conditions | 1 |
Paths | 1 |
Total Lines | 106 |
Code Lines | 68 |
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 |
||
18 | public function testGetGlobalPermissions(): void |
||
19 | { |
||
20 | $user = new User(); |
||
21 | $actual = $user->getGlobalPermissions(); |
||
22 | $expected = [ |
||
23 | 'account' => [ |
||
24 | 'create' => true, |
||
25 | ], |
||
26 | 'accountingDocument' => [ |
||
27 | 'create' => true, |
||
28 | ], |
||
29 | 'bookable' => [ |
||
30 | 'create' => false, |
||
31 | ], |
||
32 | 'bookableMetadata' => [ |
||
33 | 'create' => false, |
||
34 | ], |
||
35 | 'bookableTag' => [ |
||
36 | 'create' => false, |
||
37 | ], |
||
38 | 'booking' => [ |
||
39 | 'create' => true, |
||
40 | ], |
||
41 | 'category' => [ |
||
42 | 'create' => false, |
||
43 | ], |
||
44 | 'country' => [ |
||
45 | 'create' => false, |
||
46 | ], |
||
47 | 'expenseClaim' => [ |
||
48 | 'create' => true, |
||
49 | ], |
||
50 | 'image' => [ |
||
51 | 'create' => false, |
||
52 | ], |
||
53 | 'license' => [ |
||
54 | 'create' => false, |
||
55 | ], |
||
56 | 'message' => [ |
||
57 | 'create' => false, |
||
58 | ], |
||
59 | 'user' => [ |
||
60 | 'create' => true, |
||
61 | ], |
||
62 | 'userTag' => [ |
||
63 | 'create' => false, |
||
64 | ], |
||
65 | |||
66 | ]; |
||
67 | self::assertEquals($expected, $actual); |
||
68 | |||
69 | $expectedForAdmin = [ |
||
70 | 'account' => [ |
||
71 | 'create' => true, |
||
72 | ], |
||
73 | 'accountingDocument' => [ |
||
74 | 'create' => true, |
||
75 | ], |
||
76 | 'bookable' => [ |
||
77 | 'create' => true, |
||
78 | ], |
||
79 | 'bookableMetadata' => [ |
||
80 | 'create' => true, |
||
81 | ], |
||
82 | 'bookableTag' => [ |
||
83 | 'create' => true, |
||
84 | ], |
||
85 | 'booking' => [ |
||
86 | 'create' => true, |
||
87 | ], |
||
88 | 'category' => [ |
||
89 | 'create' => true, |
||
90 | ], |
||
91 | 'country' => [ |
||
92 | 'create' => false, |
||
93 | ], |
||
94 | 'expenseClaim' => [ |
||
95 | 'create' => true, |
||
96 | ], |
||
97 | 'image' => [ |
||
98 | 'create' => true, |
||
99 | ], |
||
100 | 'license' => [ |
||
101 | 'create' => true, |
||
102 | ], |
||
103 | 'message' => [ |
||
104 | 'create' => false, |
||
105 | ], |
||
106 | 'user' => [ |
||
107 | 'create' => true, |
||
108 | ], |
||
109 | 'userTag' => [ |
||
110 | 'create' => true, |
||
111 | ], |
||
112 | |||
113 | ]; |
||
114 | |||
115 | User::setCurrent($user); |
||
116 | self::assertSame($user, User::getCurrent()); |
||
117 | |||
118 | $admin = new User(User::ROLE_ADMINISTRATOR); |
||
119 | $actualForAdmin = $admin->getGlobalPermissions(); |
||
120 | |||
121 | self::assertEquals($expectedForAdmin, $actualForAdmin); |
||
122 | self::assertSame($user, User::getCurrent()); |
||
123 | self::assertNotEquals($expectedForAdmin, $expected); |
||
124 | } |
||
228 |