| Conditions | 1 |
| Paths | 1 |
| Total Lines | 120 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 170 | public function testRoles() |
||
| 171 | { |
||
| 172 | /** |
||
| 173 | * @var Blog $firstBlog |
||
| 174 | */ |
||
| 175 | $firstBlog = $this->objFromFixture(Blog::class, 'FirstBlog'); |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @var Blog $fourthBlog |
||
| 179 | */ |
||
| 180 | $fourthBlog = $this->objFromFixture(Blog::class, 'FourthBlog'); |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @var BlogPost $postA |
||
| 184 | */ |
||
| 185 | $postA = $this->objFromFixture(BlogPost::class, 'PostA'); |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @var BlogPost $postB |
||
| 189 | */ |
||
| 190 | $postB = $this->objFromFixture(BlogPost::class, 'PostB'); |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @var BlogPost $postC |
||
| 194 | */ |
||
| 195 | $postC = $this->objFromFixture(BlogPost::class, 'PostC'); |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @var Member $editor |
||
| 199 | */ |
||
| 200 | $editor = $this->objFromFixture(Member::class, 'BlogEditor'); |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @var Member $writer |
||
| 204 | */ |
||
| 205 | $writer = $this->objFromFixture(Member::class, 'Writer'); |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @var Member $contributor |
||
| 209 | */ |
||
| 210 | $contributor = $this->objFromFixture(Member::class, 'Contributor'); |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @var Member $visitor |
||
| 214 | */ |
||
| 215 | $visitor = $this->objFromFixture(Member::class, 'Visitor'); |
||
| 216 | |||
| 217 | $this->assertEquals('Editor', $fourthBlog->RoleOf($editor)); |
||
| 218 | $this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor)); |
||
| 219 | $this->assertEquals('Writer', $fourthBlog->RoleOf($writer)); |
||
| 220 | $this->assertEmpty($fourthBlog->RoleOf($visitor)); |
||
| 221 | $this->assertEquals('Author', $postA->RoleOf($writer)); |
||
| 222 | $this->assertEquals('Author', $postA->RoleOf($contributor)); |
||
| 223 | $this->assertEquals('Editor', $postA->RoleOf($editor)); |
||
| 224 | $this->assertEmpty($postA->RoleOf($visitor)); |
||
| 225 | |||
| 226 | // Test RoleOf with string values given |
||
| 227 | $this->assertEquals('Editor', $fourthBlog->RoleOf((string)(int)$editor->ID)); |
||
| 228 | $this->assertEquals('Contributor', $fourthBlog->RoleOf((string)(int)$contributor->ID)); |
||
| 229 | $this->assertEquals('Writer', $fourthBlog->RoleOf((string)(int)$writer->ID)); |
||
| 230 | $this->assertEmpty($fourthBlog->RoleOf((string)(int)$visitor->ID)); |
||
| 231 | $this->assertEquals('Author', $postA->RoleOf((string)(int)$writer->ID)); |
||
| 232 | $this->assertEquals('Author', $postA->RoleOf((string)(int)$contributor->ID)); |
||
| 233 | $this->assertEquals('Editor', $postA->RoleOf((string)(int)$editor->ID)); |
||
| 234 | $this->assertEmpty($postA->RoleOf((string)(int)$visitor->ID)); |
||
| 235 | |||
| 236 | // Test RoleOf with int values given |
||
| 237 | $this->assertEquals('Editor', $fourthBlog->RoleOf((int)$editor->ID)); |
||
| 238 | $this->assertEquals('Contributor', $fourthBlog->RoleOf((int)$contributor->ID)); |
||
| 239 | $this->assertEquals('Writer', $fourthBlog->RoleOf((int)$writer->ID)); |
||
| 240 | $this->assertEmpty($fourthBlog->RoleOf((int)$visitor->ID)); |
||
| 241 | $this->assertEquals('Author', $postA->RoleOf((int)$writer->ID)); |
||
| 242 | $this->assertEquals('Author', $postA->RoleOf((int)$contributor->ID)); |
||
| 243 | $this->assertEquals('Editor', $postA->RoleOf((int)$editor->ID)); |
||
| 244 | $this->assertEmpty($postA->RoleOf((int)$visitor->ID)); |
||
| 245 | |||
| 246 | $this->assertTrue($fourthBlog->canEdit($editor)); |
||
| 247 | $this->assertFalse($firstBlog->canEdit($editor)); |
||
| 248 | $this->assertTrue($fourthBlog->canAddChildren($editor)); |
||
| 249 | $this->assertFalse($firstBlog->canAddChildren($editor)); |
||
| 250 | $this->assertTrue($postA->canEdit($editor)); |
||
| 251 | $this->assertTrue($postB->canEdit($editor)); |
||
| 252 | $this->assertTrue($postC->canEdit($editor)); |
||
| 253 | $this->assertTrue($postA->canPublish($editor)); |
||
| 254 | $this->assertTrue($postB->canPublish($editor)); |
||
| 255 | $this->assertTrue($postC->canPublish($editor)); |
||
| 256 | |||
| 257 | $this->assertFalse($fourthBlog->canEdit($writer)); |
||
| 258 | $this->assertFalse($firstBlog->canEdit($writer)); |
||
| 259 | $this->assertTrue($fourthBlog->canAddChildren($writer)); |
||
| 260 | $this->assertFalse($firstBlog->canAddChildren($writer)); |
||
| 261 | $this->assertTrue($postA->canEdit($writer)); |
||
| 262 | $this->assertFalse($postB->canEdit($writer)); |
||
| 263 | $this->assertTrue($postC->canEdit($writer)); |
||
| 264 | $this->assertTrue($postA->canPublish($writer)); |
||
| 265 | $this->assertFalse($postB->canPublish($writer)); |
||
| 266 | $this->assertTrue($postC->canPublish($writer)); |
||
| 267 | |||
| 268 | $this->assertFalse($fourthBlog->canEdit($contributor)); |
||
| 269 | $this->assertFalse($firstBlog->canEdit($contributor)); |
||
| 270 | $this->assertTrue($fourthBlog->canAddChildren($contributor)); |
||
| 271 | $this->assertFalse($firstBlog->canAddChildren($contributor)); |
||
| 272 | $this->assertTrue($postA->canEdit($contributor)); |
||
| 273 | $this->assertFalse($postB->canEdit($contributor)); |
||
| 274 | $this->assertTrue($postC->canEdit($contributor)); |
||
| 275 | $this->assertFalse($postA->canPublish($contributor)); |
||
| 276 | $this->assertFalse($postB->canPublish($contributor)); |
||
| 277 | $this->assertFalse($postC->canPublish($contributor)); |
||
| 278 | |||
| 279 | $this->assertFalse($fourthBlog->canEdit($visitor)); |
||
| 280 | $this->assertFalse($firstBlog->canEdit($visitor)); |
||
| 281 | $this->assertFalse($fourthBlog->canAddChildren($visitor)); |
||
| 282 | $this->assertFalse($firstBlog->canAddChildren($visitor)); |
||
| 283 | $this->assertFalse($postA->canEdit($visitor)); |
||
| 284 | $this->assertFalse($postB->canEdit($visitor)); |
||
| 285 | $this->assertFalse($postC->canEdit($visitor)); |
||
| 286 | $this->assertFalse($postA->canPublish($visitor)); |
||
| 287 | $this->assertFalse($postB->canPublish($visitor)); |
||
| 288 | $this->assertFalse($postC->canPublish($visitor)); |
||
| 289 | } |
||
| 290 | |||
| 366 |