| Conditions | 1 |
| Paths | 1 |
| Total Lines | 119 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 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 |
||
| 147 | public function testRoles() { |
||
| 148 | /** |
||
| 149 | * @var Blog $firstBlog |
||
| 150 | */ |
||
| 151 | $firstBlog = $this->objFromFixture('Blog', 'FirstBlog'); |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var Blog $fourthBlog |
||
| 155 | */ |
||
| 156 | $fourthBlog = $this->objFromFixture('Blog', 'FourthBlog'); |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var BlogPost $postA |
||
| 160 | */ |
||
| 161 | $postA = $this->objFromFixture('BlogPost', 'PostA'); |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var BlogPost $postB |
||
| 165 | */ |
||
| 166 | $postB = $this->objFromFixture('BlogPost', 'PostB'); |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var BlogPost $postC |
||
| 170 | */ |
||
| 171 | $postC = $this->objFromFixture('BlogPost', 'PostC'); |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var Member $editor |
||
| 175 | */ |
||
| 176 | $editor = $this->objFromFixture('Member', 'BlogEditor'); |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var Member $writer |
||
| 180 | */ |
||
| 181 | $writer = $this->objFromFixture('Member', 'Writer'); |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @var Member $contributor |
||
| 185 | */ |
||
| 186 | $contributor = $this->objFromFixture('Member', 'Contributor'); |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var Member $visitor |
||
| 190 | */ |
||
| 191 | $visitor = $this->objFromFixture('Member', 'Visitor'); |
||
| 192 | |||
| 193 | $this->assertEquals('Editor', $fourthBlog->RoleOf($editor)); |
||
| 194 | $this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor)); |
||
| 195 | $this->assertEquals('Writer', $fourthBlog->RoleOf($writer)); |
||
| 196 | $this->assertEmpty($fourthBlog->RoleOf($visitor)); |
||
| 197 | $this->assertEquals('Author', $postA->RoleOf($writer)); |
||
| 198 | $this->assertEquals('Author', $postA->RoleOf($contributor)); |
||
| 199 | $this->assertEquals('Editor', $postA->RoleOf($editor)); |
||
| 200 | $this->assertEmpty($postA->RoleOf($visitor)); |
||
| 201 | |||
| 202 | // Test RoleOf with string values given |
||
| 203 | $this->assertEquals('Editor', $fourthBlog->RoleOf((string)(int)$editor->ID)); |
||
| 204 | $this->assertEquals('Contributor', $fourthBlog->RoleOf((string)(int)$contributor->ID)); |
||
| 205 | $this->assertEquals('Writer', $fourthBlog->RoleOf((string)(int)$writer->ID)); |
||
| 206 | $this->assertEmpty($fourthBlog->RoleOf((string)(int)$visitor->ID)); |
||
| 207 | $this->assertEquals('Author', $postA->RoleOf((string)(int)$writer->ID)); |
||
| 208 | $this->assertEquals('Author', $postA->RoleOf((string)(int)$contributor->ID)); |
||
| 209 | $this->assertEquals('Editor', $postA->RoleOf((string)(int)$editor->ID)); |
||
| 210 | $this->assertEmpty($postA->RoleOf((string)(int)$visitor->ID)); |
||
| 211 | |||
| 212 | // Test RoleOf with int values given |
||
| 213 | $this->assertEquals('Editor', $fourthBlog->RoleOf((int)$editor->ID)); |
||
| 214 | $this->assertEquals('Contributor', $fourthBlog->RoleOf((int)$contributor->ID)); |
||
| 215 | $this->assertEquals('Writer', $fourthBlog->RoleOf((int)$writer->ID)); |
||
| 216 | $this->assertEmpty($fourthBlog->RoleOf((int)$visitor->ID)); |
||
| 217 | $this->assertEquals('Author', $postA->RoleOf((int)$writer->ID)); |
||
| 218 | $this->assertEquals('Author', $postA->RoleOf((int)$contributor->ID)); |
||
| 219 | $this->assertEquals('Editor', $postA->RoleOf((int)$editor->ID)); |
||
| 220 | $this->assertEmpty($postA->RoleOf((int)$visitor->ID)); |
||
| 221 | |||
| 222 | $this->assertTrue($fourthBlog->canEdit($editor)); |
||
| 223 | $this->assertFalse($firstBlog->canEdit($editor)); |
||
| 224 | $this->assertTrue($fourthBlog->canAddChildren($editor)); |
||
| 225 | $this->assertFalse($firstBlog->canAddChildren($editor)); |
||
| 226 | $this->assertTrue($postA->canEdit($editor)); |
||
| 227 | $this->assertTrue($postB->canEdit($editor)); |
||
| 228 | $this->assertTrue($postC->canEdit($editor)); |
||
| 229 | $this->assertTrue($postA->canPublish($editor)); |
||
| 230 | $this->assertTrue($postB->canPublish($editor)); |
||
| 231 | $this->assertTrue($postC->canPublish($editor)); |
||
| 232 | |||
| 233 | $this->assertFalse($fourthBlog->canEdit($writer)); |
||
| 234 | $this->assertFalse($firstBlog->canEdit($writer)); |
||
| 235 | $this->assertTrue($fourthBlog->canAddChildren($writer)); |
||
| 236 | $this->assertFalse($firstBlog->canAddChildren($writer)); |
||
| 237 | $this->assertTrue($postA->canEdit($writer)); |
||
| 238 | $this->assertFalse($postB->canEdit($writer)); |
||
| 239 | $this->assertTrue($postC->canEdit($writer)); |
||
| 240 | $this->assertTrue($postA->canPublish($writer)); |
||
| 241 | $this->assertFalse($postB->canPublish($writer)); |
||
| 242 | $this->assertTrue($postC->canPublish($writer)); |
||
| 243 | |||
| 244 | $this->assertFalse($fourthBlog->canEdit($contributor)); |
||
| 245 | $this->assertFalse($firstBlog->canEdit($contributor)); |
||
| 246 | $this->assertTrue($fourthBlog->canAddChildren($contributor)); |
||
| 247 | $this->assertFalse($firstBlog->canAddChildren($contributor)); |
||
| 248 | $this->assertTrue($postA->canEdit($contributor)); |
||
| 249 | $this->assertFalse($postB->canEdit($contributor)); |
||
| 250 | $this->assertTrue($postC->canEdit($contributor)); |
||
| 251 | $this->assertFalse($postA->canPublish($contributor)); |
||
| 252 | $this->assertFalse($postB->canPublish($contributor)); |
||
| 253 | $this->assertFalse($postC->canPublish($contributor)); |
||
| 254 | |||
| 255 | $this->assertFalse($fourthBlog->canEdit($visitor)); |
||
| 256 | $this->assertFalse($firstBlog->canEdit($visitor)); |
||
| 257 | $this->assertFalse($fourthBlog->canAddChildren($visitor)); |
||
| 258 | $this->assertFalse($firstBlog->canAddChildren($visitor)); |
||
| 259 | $this->assertFalse($postA->canEdit($visitor)); |
||
| 260 | $this->assertFalse($postB->canEdit($visitor)); |
||
| 261 | $this->assertFalse($postC->canEdit($visitor)); |
||
| 262 | $this->assertFalse($postA->canPublish($visitor)); |
||
| 263 | $this->assertFalse($postB->canPublish($visitor)); |
||
| 264 | $this->assertFalse($postC->canPublish($visitor)); |
||
| 265 | } |
||
| 266 | |||
| 335 |
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.