Complex classes like UriTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UriTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class UriTest extends TestCase |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var Uri |
||
| 27 | */ |
||
| 28 | private $uri; |
||
| 29 | |||
| 30 | protected function setUp(): void |
||
| 36 | |||
| 37 | protected function tearDown(): void |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @covers ::__toString |
||
| 44 | * @covers ::formatHost |
||
| 45 | * @covers ::formatRegisteredName |
||
| 46 | * @covers ::formatQueryAndFragment |
||
| 47 | * @covers ::formatPort |
||
| 48 | * @covers ::formatUserInfo |
||
| 49 | * @covers ::formatScheme |
||
| 50 | */ |
||
| 51 | public function testAutomaticUrlNormalization(): void |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @covers ::__toString |
||
| 60 | * @covers ::formatHost |
||
| 61 | */ |
||
| 62 | public function testAutomaticUrlNormalizationBis(): void |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @covers ::__toString |
||
| 72 | * @covers ::formatScheme |
||
| 73 | */ |
||
| 74 | public function testConstructingUrisWithSchemesWithNonLeadingDigits(): void |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @covers ::__toString |
||
| 82 | * @covers ::formatScheme |
||
| 83 | * @covers ::withScheme |
||
| 84 | */ |
||
| 85 | public function testSettingSchemesWithNonLeadingDigits(): void |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @covers ::getUriString |
||
| 94 | * @covers ::__toString |
||
| 95 | * @covers ::formatUserInfo |
||
| 96 | * @covers ::formatQueryAndFragment |
||
| 97 | */ |
||
| 98 | public function testPreserveComponentsOnInstantiation(): void |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @covers ::getScheme |
||
| 106 | * @covers ::withScheme |
||
| 107 | */ |
||
| 108 | public function testScheme(): void |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @covers ::getUserInfo |
||
| 121 | * @covers ::withUserInfo |
||
| 122 | * @covers ::formatUserInfo |
||
| 123 | */ |
||
| 124 | public function testUserInfo(): void |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @covers ::getHost |
||
| 140 | * @covers ::withHost |
||
| 141 | * @covers ::formatHost |
||
| 142 | * @covers ::formatIp |
||
| 143 | * @covers ::formatRegisteredName |
||
| 144 | */ |
||
| 145 | public function testHost(): void |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @covers ::getAuthority |
||
| 154 | */ |
||
| 155 | public function testGetAuthority(): void |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @covers ::withUserInfo |
||
| 162 | * @covers ::withPort |
||
| 163 | * @covers ::withScheme |
||
| 164 | * @covers ::withHost |
||
| 165 | */ |
||
| 166 | public function testRemoveAuthority(): void |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @covers ::getPort |
||
| 178 | * @covers ::withPort |
||
| 179 | * @covers ::formatPort |
||
| 180 | */ |
||
| 181 | public function testPort(): void |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @covers ::getPath |
||
| 194 | * @covers ::withPath |
||
| 195 | */ |
||
| 196 | public function testPath(): void |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @covers ::getQuery |
||
| 209 | * @covers ::withQuery |
||
| 210 | */ |
||
| 211 | public function testQuery(): void |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @covers ::getFragment |
||
| 224 | * @covers ::withFragment |
||
| 225 | */ |
||
| 226 | public function testFragment(): void |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @covers ::getIDNAErrors |
||
| 239 | * @covers ::formatHost |
||
| 240 | */ |
||
| 241 | public function testCannotConvertInvalidHost(): void |
||
| 246 | |||
| 247 | public function testWithSchemeFailedWithInvalidSchemeValue(): void |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @covers ::filterString |
||
| 255 | */ |
||
| 256 | public function testWithInvalidCharacters(): void |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @covers ::assertValidState |
||
| 264 | */ |
||
| 265 | public function testWithPathFailedWithInvalidChars(): void |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @covers ::assertValidState |
||
| 273 | */ |
||
| 274 | public function testWithPathFailedWithInvalidPathRelativeToTheAuthority(): void |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @covers ::formatRegisteredName |
||
| 282 | * @covers ::withHost |
||
| 283 | */ |
||
| 284 | public function testModificationFailedWithInvalidHost(): void |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @covers ::assertValidState |
||
| 292 | * @dataProvider missingAuthorityProvider |
||
| 293 | */ |
||
| 294 | public function testModificationFailedWithMissingAuthority(string $path): void |
||
| 302 | |||
| 303 | /** |
||
| 304 | * @covers ::assertValidState |
||
| 305 | */ |
||
| 306 | public function missingAuthorityProvider(): array |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @covers ::__toString |
||
| 316 | * @covers ::formatHost |
||
| 317 | * @covers ::formatRegisteredName |
||
| 318 | * @covers ::formatQueryAndFragment |
||
| 319 | * @covers ::formatPort |
||
| 320 | * @covers ::formatUserInfo |
||
| 321 | */ |
||
| 322 | public function testEmptyValueDetection(): void |
||
| 327 | |||
| 328 | public function testPathDetection(): void |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @covers ::filterString |
||
| 336 | * @covers ::withPath |
||
| 337 | */ |
||
| 338 | public function testWithPathThrowTypeErrorOnWrongType(): void |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @dataProvider setStateDataProvider |
||
| 346 | * |
||
| 347 | * @covers ::__set_state |
||
| 348 | */ |
||
| 349 | public function testSetState(Uri $uri): void |
||
| 353 | |||
| 354 | public function setStateDataProvider(): array |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @covers ::__debugInfo |
||
| 371 | */ |
||
| 372 | public function testDebugInfo(): void |
||
| 379 | |||
| 380 | public function testJsonSerialize(): void |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @covers ::createFromComponents |
||
| 388 | * @covers ::formatRegisteredName |
||
| 389 | */ |
||
| 390 | public function testCreateFromComponents(): void |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @covers ::formatPort |
||
| 401 | * @covers ::withPort |
||
| 402 | */ |
||
| 403 | public function testModificationFailedWithInvalidPort(): void |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @covers ::formatPort |
||
| 411 | * @covers ::withPort |
||
| 412 | */ |
||
| 413 | public function testModificationFailedWithInvalidPort2(): void |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @covers ::formatIp |
||
| 421 | */ |
||
| 422 | public function testCreateFromComponentsHandlesScopedIpv6(): void |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @covers ::formatIp |
||
| 433 | */ |
||
| 434 | public function testCreateFromComponentsHandlesIpvFuture(): void |
||
| 442 | |||
| 443 | |||
| 444 | /** |
||
| 445 | * @covers ::formatIp |
||
| 446 | */ |
||
| 447 | public function testCreateFromComponentsThrowsOnInvalidIpvFuture(): void |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @covers ::filterString |
||
| 455 | */ |
||
| 456 | public function testCreateFromComponentsThrowsExceptionWithInvalidChars(): void |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @covers ::formatIp |
||
| 464 | */ |
||
| 465 | public function testCreateFromComponentsThrowsException(): void |
||
| 470 | |||
| 471 | /** |
||
| 472 | * @covers ::formatIp |
||
| 473 | */ |
||
| 474 | public function testCreateFromComponentsThrowsException2(): void |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @covers ::formatIp |
||
| 482 | */ |
||
| 483 | public function testCreateFromComponentsThrowsException3(): void |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @covers ::formatIp |
||
| 491 | */ |
||
| 492 | public function testCreateFromComponentsThrowsException4(): void |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @covers ::formatRegisteredName |
||
| 500 | * @covers ::getIDNAErrors |
||
| 501 | */ |
||
| 502 | public function testCreateFromComponentsThrowsException5(): void |
||
| 507 | |||
| 508 | /** |
||
| 509 | * @covers ::formatRegisteredName |
||
| 510 | * @covers ::getIDNAErrors |
||
| 511 | */ |
||
| 512 | public function testCreateFromComponentsThrowsException6(): void |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @covers ::formatRegisteredName |
||
| 520 | */ |
||
| 521 | public function testCreateFromComponentsThrowsException7(): void |
||
| 526 | |||
| 527 | /** |
||
| 528 | * @covers ::formatRegisteredName |
||
| 529 | */ |
||
| 530 | public function testCreateFromComponentsWorksWithPunycode(): void |
||
| 535 | |||
| 536 | /** |
||
| 537 | * @covers ::formatPath |
||
| 538 | */ |
||
| 539 | public function testReservedCharsInPathUnencoded(): void |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @dataProvider userInfoProvider |
||
| 554 | * @param ?string $credential |
||
|
|
|||
| 555 | */ |
||
| 556 | public function testWithUserInfoEncodesUsernameAndPassword(string $user, ?string $credential, string $expected): void |
||
| 562 | |||
| 563 | public function userInfoProvider(): array |
||
| 575 | |||
| 576 | public function testIssue167ExceptionReasonMisleadingMessage(): void |
||
| 583 | |||
| 584 | public function testIssue171TheEmptySchemeShouldThrow(): void |
||
| 591 | } |
||
| 592 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.