| Conditions | 1 |
| Paths | 1 |
| Total Lines | 113 |
| Code Lines | 74 |
| 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 | $user->setSite(Site::Dilps); |
||
| 22 | $actual = $user->getGlobalPermissions(); |
||
| 23 | $expected = [ |
||
| 24 | 'artist' => [ |
||
| 25 | 'create' => true, |
||
| 26 | ], |
||
| 27 | 'card' => [ |
||
| 28 | 'create' => true, |
||
| 29 | ], |
||
| 30 | 'change' => [ |
||
| 31 | 'create' => true, |
||
| 32 | ], |
||
| 33 | 'collection' => [ |
||
| 34 | 'create' => true, |
||
| 35 | ], |
||
| 36 | 'country' => [ |
||
| 37 | 'create' => false, |
||
| 38 | ], |
||
| 39 | 'dating' => [ |
||
| 40 | 'create' => false, |
||
| 41 | ], |
||
| 42 | 'institution' => [ |
||
| 43 | 'create' => true, |
||
| 44 | ], |
||
| 45 | 'tag' => [ |
||
| 46 | 'create' => true, |
||
| 47 | ], |
||
| 48 | 'user' => [ |
||
| 49 | 'create' => false, |
||
| 50 | ], |
||
| 51 | 'domain' => [ |
||
| 52 | 'create' => false, |
||
| 53 | ], |
||
| 54 | 'documentType' => [ |
||
| 55 | 'create' => false, |
||
| 56 | ], |
||
| 57 | 'news' => [ |
||
| 58 | 'create' => false, |
||
| 59 | ], |
||
| 60 | 'period' => [ |
||
| 61 | 'create' => false, |
||
| 62 | ], |
||
| 63 | 'material' => [ |
||
| 64 | 'create' => false, |
||
| 65 | ], |
||
| 66 | 'antiqueName' => [ |
||
| 67 | 'create' => false, |
||
| 68 | ], |
||
| 69 | ]; |
||
| 70 | |||
| 71 | self::assertEquals($expected, $actual); |
||
| 72 | |||
| 73 | $expectedForAdmin = [ |
||
| 74 | 'artist' => [ |
||
| 75 | 'create' => true, |
||
| 76 | ], |
||
| 77 | 'card' => [ |
||
| 78 | 'create' => true, |
||
| 79 | ], |
||
| 80 | 'change' => [ |
||
| 81 | 'create' => true, |
||
| 82 | ], |
||
| 83 | 'collection' => [ |
||
| 84 | 'create' => true, |
||
| 85 | ], |
||
| 86 | 'country' => [ |
||
| 87 | 'create' => false, |
||
| 88 | ], |
||
| 89 | 'dating' => [ |
||
| 90 | 'create' => false, |
||
| 91 | ], |
||
| 92 | 'institution' => [ |
||
| 93 | 'create' => true, |
||
| 94 | ], |
||
| 95 | 'tag' => [ |
||
| 96 | 'create' => true, |
||
| 97 | ], |
||
| 98 | 'user' => [ |
||
| 99 | 'create' => true, |
||
| 100 | ], |
||
| 101 | 'domain' => [ |
||
| 102 | 'create' => true, |
||
| 103 | ], |
||
| 104 | 'documentType' => [ |
||
| 105 | 'create' => true, |
||
| 106 | ], |
||
| 107 | 'news' => [ |
||
| 108 | 'create' => true, |
||
| 109 | ], |
||
| 110 | 'period' => [ |
||
| 111 | 'create' => true, |
||
| 112 | ], |
||
| 113 | 'material' => [ |
||
| 114 | 'create' => true, |
||
| 115 | ], |
||
| 116 | 'antiqueName' => [ |
||
| 117 | 'create' => true, |
||
| 118 | ], |
||
| 119 | ]; |
||
| 120 | |||
| 121 | User::setCurrent($user); |
||
| 122 | self::assertSame($user, User::getCurrent()); |
||
| 123 | |||
| 124 | $admin = new User(User::ROLE_ADMINISTRATOR); |
||
| 125 | $admin->setSite(Site::Dilps); |
||
| 126 | $actualForAdmin = $admin->getGlobalPermissions(); |
||
| 127 | |||
| 128 | self::assertEquals($expectedForAdmin, $actualForAdmin); |
||
| 129 | self::assertSame($user, User::getCurrent()); |
||
| 130 | self::assertNotEquals($expectedForAdmin, $expected); |
||
| 131 | } |
||
| 190 |