Complex classes like UnspecifiedType 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 UnspecifiedType, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class UnspecifiedType implements ElementBase |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * The wrapped element. |
||
| 21 | * |
||
| 22 | * @var Element |
||
| 23 | */ |
||
| 24 | private $_element; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Constructor. |
||
| 28 | * |
||
| 29 | * @param Element $el |
||
| 30 | */ |
||
| 31 | 112 | public function __construct(Element $el) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Initialize from DER data. |
||
| 38 | * |
||
| 39 | * @param string $data DER encoded data |
||
| 40 | * @return self |
||
| 41 | */ |
||
| 42 | 15 | public static function fromDER(string $data): self |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Initialize from ElementBase interface. |
||
| 49 | * |
||
| 50 | * @param ElementBase $el |
||
| 51 | * @return self |
||
| 52 | */ |
||
| 53 | 2 | public static function fromElementBase(ElementBase $el): self |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Compatibility method to dispatch calls to the wrapped element. |
||
| 64 | * |
||
| 65 | * @deprecated Use <code>as*</code> accessor methods to ensure strict type |
||
| 66 | * @param string $mtd Method name |
||
| 67 | * @param array $args Arguments |
||
| 68 | * @return mixed |
||
| 69 | */ |
||
| 70 | 2 | public function __call($mtd, array $args) |
|
| 74 | |||
| 75 | /** |
||
| 76 | * Get the wrapped element as a context specific tagged type. |
||
| 77 | * |
||
| 78 | * @throws \UnexpectedValueException If the element is not tagged |
||
| 79 | * @return TaggedType |
||
| 80 | */ |
||
| 81 | 2 | public function asTagged(): TaggedType |
|
| 89 | |||
| 90 | /** |
||
| 91 | * Get the wrapped element as an application specific type. |
||
| 92 | * |
||
| 93 | * @throws \UnexpectedValueException If element is not application specific |
||
| 94 | * @return \ASN1\Type\Tagged\ApplicationType |
||
| 95 | */ |
||
| 96 | 2 | public function asApplication(): Tagged\ApplicationType |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Get the wrapped element as a private tagged type. |
||
| 108 | * |
||
| 109 | * @throws \UnexpectedValueException If element is not using private tagging |
||
| 110 | * @return \ASN1\Type\Tagged\PrivateType |
||
| 111 | */ |
||
| 112 | 2 | public function asPrivate(): Tagged\PrivateType |
|
| 120 | |||
| 121 | /** |
||
| 122 | * Get the wrapped element as a boolean type. |
||
| 123 | * |
||
| 124 | * @throws \UnexpectedValueException If the element is not a boolean |
||
| 125 | * @return \ASN1\Type\Primitive\Boolean |
||
| 126 | */ |
||
| 127 | 4 | public function asBoolean(): Primitive\Boolean |
|
| 135 | |||
| 136 | /** |
||
| 137 | * Get the wrapped element as an integer type. |
||
| 138 | * |
||
| 139 | * @throws \UnexpectedValueException If the element is not an integer |
||
| 140 | * @return \ASN1\Type\Primitive\Integer |
||
| 141 | */ |
||
| 142 | 6 | public function asInteger(): Primitive\Integer |
|
| 150 | |||
| 151 | /** |
||
| 152 | * Get the wrapped element as a bit string type. |
||
| 153 | * |
||
| 154 | * @throws \UnexpectedValueException If the element is not a bit string |
||
| 155 | * @return \ASN1\Type\Primitive\BitString |
||
| 156 | */ |
||
| 157 | 2 | public function asBitString(): Primitive\BitString |
|
| 165 | |||
| 166 | /** |
||
| 167 | * Get the wrapped element as an octet string type. |
||
| 168 | * |
||
| 169 | * @throws \UnexpectedValueException If the element is not an octet string |
||
| 170 | * @return \ASN1\Type\Primitive\OctetString |
||
| 171 | */ |
||
| 172 | 2 | public function asOctetString(): Primitive\OctetString |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Get the wrapped element as a null type. |
||
| 183 | * |
||
| 184 | * @throws \UnexpectedValueException If the element is not a null |
||
| 185 | * @return \ASN1\Type\Primitive\NullType |
||
| 186 | */ |
||
| 187 | 10 | public function asNull(): Primitive\NullType |
|
| 195 | |||
| 196 | /** |
||
| 197 | * Get the wrapped element as an object identifier type. |
||
| 198 | * |
||
| 199 | * @throws \UnexpectedValueException If the element is not an object |
||
| 200 | * identifier |
||
| 201 | * @return \ASN1\Type\Primitive\ObjectIdentifier |
||
| 202 | */ |
||
| 203 | 12 | public function asObjectIdentifier(): Primitive\ObjectIdentifier |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Get the wrapped element as an object descriptor type. |
||
| 215 | * |
||
| 216 | * @throws \UnexpectedValueException If the element is not an object |
||
| 217 | * descriptor |
||
| 218 | * @return \ASN1\Type\Primitive\ObjectDescriptor |
||
| 219 | */ |
||
| 220 | 2 | public function asObjectDescriptor(): Primitive\ObjectDescriptor |
|
| 229 | |||
| 230 | /** |
||
| 231 | * Get the wrapped element as a real type. |
||
| 232 | * |
||
| 233 | * @throws \UnexpectedValueException If the element is not a real |
||
| 234 | * @return \ASN1\Type\Primitive\Real |
||
| 235 | */ |
||
| 236 | 2 | public function asReal(): Primitive\Real |
|
| 244 | |||
| 245 | /** |
||
| 246 | * Get the wrapped element as an enumerated type. |
||
| 247 | * |
||
| 248 | * @throws \UnexpectedValueException If the element is not an enumerated |
||
| 249 | * @return \ASN1\Type\Primitive\Enumerated |
||
| 250 | */ |
||
| 251 | 2 | public function asEnumerated(): Primitive\Enumerated |
|
| 259 | |||
| 260 | /** |
||
| 261 | * Get the wrapped element as a UTF8 string type. |
||
| 262 | * |
||
| 263 | * @throws \UnexpectedValueException If the element is not a UTF8 string |
||
| 264 | * @return \ASN1\Type\Primitive\UTF8String |
||
| 265 | */ |
||
| 266 | 2 | public function asUTF8String(): Primitive\UTF8String |
|
| 274 | |||
| 275 | /** |
||
| 276 | * Get the wrapped element as a relative OID type. |
||
| 277 | * |
||
| 278 | * @throws \UnexpectedValueException If the element is not a relative OID |
||
| 279 | * @return \ASN1\Type\Primitive\RelativeOID |
||
| 280 | */ |
||
| 281 | 2 | public function asRelativeOID(): Primitive\RelativeOID |
|
| 289 | |||
| 290 | /** |
||
| 291 | * Get the wrapped element as a sequence type. |
||
| 292 | * |
||
| 293 | * @throws \UnexpectedValueException If the element is not a sequence |
||
| 294 | * @return \ASN1\Type\Constructed\Sequence |
||
| 295 | */ |
||
| 296 | 2 | public function asSequence(): Constructed\Sequence |
|
| 304 | |||
| 305 | /** |
||
| 306 | * Get the wrapped element as a set type. |
||
| 307 | * |
||
| 308 | * @throws \UnexpectedValueException If the element is not a set |
||
| 309 | * @return \ASN1\Type\Constructed\Set |
||
| 310 | */ |
||
| 311 | 2 | public function asSet(): Constructed\Set |
|
| 319 | |||
| 320 | /** |
||
| 321 | * Get the wrapped element as a numeric string type. |
||
| 322 | * |
||
| 323 | * @throws \UnexpectedValueException If the element is not a numeric string |
||
| 324 | * @return \ASN1\Type\Primitive\NumericString |
||
| 325 | */ |
||
| 326 | 2 | public function asNumericString(): Primitive\NumericString |
|
| 334 | |||
| 335 | /** |
||
| 336 | * Get the wrapped element as a printable string type. |
||
| 337 | * |
||
| 338 | * @throws \UnexpectedValueException If the element is not a printable |
||
| 339 | * string |
||
| 340 | * @return \ASN1\Type\Primitive\PrintableString |
||
| 341 | */ |
||
| 342 | 2 | public function asPrintableString(): Primitive\PrintableString |
|
| 350 | |||
| 351 | /** |
||
| 352 | * Get the wrapped element as a T61 string type. |
||
| 353 | * |
||
| 354 | * @throws \UnexpectedValueException If the element is not a T61 string |
||
| 355 | * @return \ASN1\Type\Primitive\T61String |
||
| 356 | */ |
||
| 357 | 2 | public function asT61String(): Primitive\T61String |
|
| 365 | |||
| 366 | /** |
||
| 367 | * Get the wrapped element as a videotex string type. |
||
| 368 | * |
||
| 369 | * @throws \UnexpectedValueException If the element is not a videotex string |
||
| 370 | * @return \ASN1\Type\Primitive\VideotexString |
||
| 371 | */ |
||
| 372 | 2 | public function asVideotexString(): Primitive\VideotexString |
|
| 380 | |||
| 381 | /** |
||
| 382 | * Get the wrapped element as a IA5 string type. |
||
| 383 | * |
||
| 384 | * @throws \UnexpectedValueException If the element is not a IA5 string |
||
| 385 | * @return \ASN1\Type\Primitive\IA5String |
||
| 386 | */ |
||
| 387 | 2 | public function asIA5String(): Primitive\IA5String |
|
| 395 | |||
| 396 | /** |
||
| 397 | * Get the wrapped element as an UTC time type. |
||
| 398 | * |
||
| 399 | * @throws \UnexpectedValueException If the element is not a UTC time |
||
| 400 | * @return \ASN1\Type\Primitive\UTCTime |
||
| 401 | */ |
||
| 402 | 2 | public function asUTCTime(): Primitive\UTCTime |
|
| 410 | |||
| 411 | /** |
||
| 412 | * Get the wrapped element as a generalized time type. |
||
| 413 | * |
||
| 414 | * @throws \UnexpectedValueException If the element is not a generalized |
||
| 415 | * time |
||
| 416 | * @return \ASN1\Type\Primitive\GeneralizedTime |
||
| 417 | */ |
||
| 418 | 2 | public function asGeneralizedTime(): Primitive\GeneralizedTime |
|
| 426 | |||
| 427 | /** |
||
| 428 | * Get the wrapped element as a graphic string type. |
||
| 429 | * |
||
| 430 | * @throws \UnexpectedValueException If the element is not a graphic string |
||
| 431 | * @return \ASN1\Type\Primitive\GraphicString |
||
| 432 | */ |
||
| 433 | 2 | public function asGraphicString(): Primitive\GraphicString |
|
| 441 | |||
| 442 | /** |
||
| 443 | * Get the wrapped element as a visible string type. |
||
| 444 | * |
||
| 445 | * @throws \UnexpectedValueException If the element is not a visible string |
||
| 446 | * @return \ASN1\Type\Primitive\VisibleString |
||
| 447 | */ |
||
| 448 | 2 | public function asVisibleString(): Primitive\VisibleString |
|
| 456 | |||
| 457 | /** |
||
| 458 | * Get the wrapped element as a general string type. |
||
| 459 | * |
||
| 460 | * @throws \UnexpectedValueException If the element is not general string |
||
| 461 | * @return \ASN1\Type\Primitive\GeneralString |
||
| 462 | */ |
||
| 463 | 2 | public function asGeneralString(): Primitive\GeneralString |
|
| 471 | |||
| 472 | /** |
||
| 473 | * Get the wrapped element as a universal string type. |
||
| 474 | * |
||
| 475 | * @throws \UnexpectedValueException If the element is not a universal |
||
| 476 | * string |
||
| 477 | * @return \ASN1\Type\Primitive\UniversalString |
||
| 478 | */ |
||
| 479 | 2 | public function asUniversalString(): Primitive\UniversalString |
|
| 487 | |||
| 488 | /** |
||
| 489 | * Get the wrapped element as a character string type. |
||
| 490 | * |
||
| 491 | * @throws \UnexpectedValueException If the element is not a character |
||
| 492 | * string |
||
| 493 | * @return \ASN1\Type\Primitive\CharacterString |
||
| 494 | */ |
||
| 495 | 2 | public function asCharacterString(): Primitive\CharacterString |
|
| 503 | |||
| 504 | /** |
||
| 505 | * Get the wrapped element as a BMP string type. |
||
| 506 | * |
||
| 507 | * @throws \UnexpectedValueException If the element is not a bmp string |
||
| 508 | * @return \ASN1\Type\Primitive\BMPString |
||
| 509 | */ |
||
| 510 | 2 | public function asBMPString(): Primitive\BMPString |
|
| 518 | |||
| 519 | /** |
||
| 520 | * Get the wrapped element as a constructed string type. |
||
| 521 | * |
||
| 522 | * @throws \UnexpectedValueException If the element is not a constructed |
||
| 523 | * string |
||
| 524 | * @return Constructed\ConstructedString |
||
| 525 | */ |
||
| 526 | 2 | public function asConstructedString(): Constructed\ConstructedString |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Get the wrapped element as any string type. |
||
| 538 | * |
||
| 539 | * @throws \UnexpectedValueException If the element is not a string |
||
| 540 | * @return StringType |
||
| 541 | */ |
||
| 542 | 2 | public function asString(): StringType |
|
| 550 | |||
| 551 | /** |
||
| 552 | * Get the wrapped element as any time type. |
||
| 553 | * |
||
| 554 | * @throws \UnexpectedValueException If the element is not a time |
||
| 555 | * @return TimeType |
||
| 556 | */ |
||
| 557 | 2 | public function asTime(): TimeType |
|
| 565 | |||
| 566 | /** |
||
| 567 | * Generate message for exceptions thrown by <code>as*</code> methods. |
||
| 568 | * |
||
| 569 | * @param int $tag Type tag of the expected element |
||
| 570 | * @return string |
||
| 571 | */ |
||
| 572 | 30 | private function _generateExceptionMessage(int $tag): string |
|
| 577 | |||
| 578 | /** |
||
| 579 | * Get textual description of the wrapped element for debugging purposes. |
||
| 580 | * |
||
| 581 | * @return string |
||
| 582 | */ |
||
| 583 | 33 | private function _typeDescriptorString(): string |
|
| 592 | |||
| 593 | /** |
||
| 594 | * |
||
| 595 | * @see \ASN1\Feature\Encodable::toDER() |
||
| 596 | * @return string |
||
| 597 | */ |
||
| 598 | 1 | public function toDER(): string |
|
| 602 | |||
| 603 | /** |
||
| 604 | * |
||
| 605 | * @see \ASN1\Feature\ElementBase::typeClass() |
||
| 606 | * @return int |
||
| 607 | */ |
||
| 608 | 2 | public function typeClass(): int |
|
| 612 | |||
| 613 | /** |
||
| 614 | * |
||
| 615 | * @see \ASN1\Feature\ElementBase::isConstructed() |
||
| 616 | * @return bool |
||
| 617 | */ |
||
| 618 | 3 | public function isConstructed(): bool |
|
| 622 | |||
| 623 | /** |
||
| 624 | * |
||
| 625 | * @see \ASN1\Feature\ElementBase::tag() |
||
| 626 | * @return int |
||
| 627 | */ |
||
| 628 | 9 | public function tag(): int |
|
| 632 | |||
| 633 | /** |
||
| 634 | * |
||
| 635 | * {@inheritdoc} |
||
| 636 | * @see \ASN1\Feature\ElementBase::isType() |
||
| 637 | * @return bool |
||
| 638 | */ |
||
| 639 | 1 | public function isType(int $tag): bool |
|
| 643 | |||
| 644 | /** |
||
| 645 | * |
||
| 646 | * @deprecated Use any <code>as*</code> accessor method first to ensure |
||
| 647 | * type strictness. |
||
| 648 | * @see \ASN1\Feature\ElementBase::expectType() |
||
| 649 | * @return ElementBase |
||
| 650 | */ |
||
| 651 | 1 | public function expectType(int $tag): ElementBase |
|
| 655 | |||
| 656 | /** |
||
| 657 | * |
||
| 658 | * @see \ASN1\Feature\ElementBase::isTagged() |
||
| 659 | * @return bool |
||
| 660 | */ |
||
| 661 | 1 | public function isTagged(): bool |
|
| 665 | |||
| 666 | /** |
||
| 667 | * |
||
| 668 | * @deprecated Use any <code>as*</code> accessor method first to ensure |
||
| 669 | * type strictness. |
||
| 670 | * @see \ASN1\Feature\ElementBase::expectTagged() |
||
| 671 | * @return TaggedType |
||
| 672 | */ |
||
| 673 | 1 | public function expectTagged($tag = null): TaggedType |
|
| 677 | |||
| 678 | /** |
||
| 679 | * |
||
| 680 | * @see \ASN1\Feature\ElementBase::asElement() |
||
| 681 | * @return Element |
||
| 682 | */ |
||
| 683 | 1 | public function asElement(): Element |
|
| 687 | |||
| 688 | /** |
||
| 689 | * |
||
| 690 | * {@inheritdoc} |
||
| 691 | * @return UnspecifiedType |
||
| 692 | */ |
||
| 693 | 1 | public function asUnspecified(): UnspecifiedType |
|
| 697 | } |
||
| 698 |