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  | 
            ||
| 18 | class UnspecifiedType implements ElementBase  | 
            ||
| 19 | { | 
            ||
| 20 | /**  | 
            ||
| 21 | * The wrapped element.  | 
            ||
| 22 | *  | 
            ||
| 23 | * @var Element  | 
            ||
| 24 | */  | 
            ||
| 25 | private $_element;  | 
            ||
| 26 | |||
| 27 | /**  | 
            ||
| 28 | * Constructor.  | 
            ||
| 29 | *  | 
            ||
| 30 | * @param Element $el  | 
            ||
| 31 | */  | 
            ||
| 32 | 100 | public function __construct(Element $el)  | 
            |
| 36 | |||
| 37 | /**  | 
            ||
| 38 | * Initialize from DER data.  | 
            ||
| 39 | *  | 
            ||
| 40 | * @param string $data DER encoded data  | 
            ||
| 41 | * @return self  | 
            ||
| 42 | */  | 
            ||
| 43 | 5 | public static function fromDER(string $data): self  | 
            |
| 47 | |||
| 48 | /**  | 
            ||
| 49 | * Initialize from ElementBase interface.  | 
            ||
| 50 | *  | 
            ||
| 51 | * @param ElementBase $el  | 
            ||
| 52 | * @return self  | 
            ||
| 53 | */  | 
            ||
| 54 | 2 | public static function fromElementBase(ElementBase $el): self  | 
            |
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * Compatibility method to dispatch calls to the wrapped element.  | 
            ||
| 65 | *  | 
            ||
| 66 | * @deprecated Use <code>as*</code> accessor methods to ensure strict type  | 
            ||
| 67 | * @param string $mtd Method name  | 
            ||
| 68 | * @param array $args Arguments  | 
            ||
| 69 | * @return mixed  | 
            ||
| 70 | */  | 
            ||
| 71 | 2 | public function __call($mtd, array $args)  | 
            |
| 75 | |||
| 76 | /**  | 
            ||
| 77 | * Get the wrapped element as a context specific tagged type.  | 
            ||
| 78 | *  | 
            ||
| 79 | * @throws \UnexpectedValueException If the element is not tagged  | 
            ||
| 80 | * @return TaggedType  | 
            ||
| 81 | */  | 
            ||
| 82 | 2 | public function asTagged(): TaggedType  | 
            |
| 90 | |||
| 91 | /**  | 
            ||
| 92 | * Get the wrapped element as an application specific type.  | 
            ||
| 93 | *  | 
            ||
| 94 | * @throws \UnexpectedValueException If element is not application specific  | 
            ||
| 95 | * @return \ASN1\Type\Tagged\ApplicationType  | 
            ||
| 96 | */  | 
            ||
| 97 | 2 | public function asApplication(): Tagged\ApplicationType  | 
            |
| 106 | |||
| 107 | /**  | 
            ||
| 108 | * Get the wrapped element as a private tagged type.  | 
            ||
| 109 | *  | 
            ||
| 110 | * @throws \UnexpectedValueException If element is not using private tagging  | 
            ||
| 111 | * @return \ASN1\Type\Tagged\PrivateType  | 
            ||
| 112 | */  | 
            ||
| 113 | 2 | public function asPrivate(): Tagged\PrivateType  | 
            |
| 121 | |||
| 122 | /**  | 
            ||
| 123 | * Get the wrapped element as a boolean type.  | 
            ||
| 124 | *  | 
            ||
| 125 | * @throws \UnexpectedValueException If the element is not a boolean  | 
            ||
| 126 | * @return \ASN1\Type\Primitive\Boolean  | 
            ||
| 127 | */  | 
            ||
| 128 | 4 | public function asBoolean(): Primitive\Boolean  | 
            |
| 136 | |||
| 137 | /**  | 
            ||
| 138 | * Get the wrapped element as an integer type.  | 
            ||
| 139 | *  | 
            ||
| 140 | * @throws \UnexpectedValueException If the element is not an integer  | 
            ||
| 141 | * @return \ASN1\Type\Primitive\Integer  | 
            ||
| 142 | */  | 
            ||
| 143 | 6 | public function asInteger(): Primitive\Integer  | 
            |
| 151 | |||
| 152 | /**  | 
            ||
| 153 | * Get the wrapped element as a bit string type.  | 
            ||
| 154 | *  | 
            ||
| 155 | * @throws \UnexpectedValueException If the element is not a bit string  | 
            ||
| 156 | * @return \ASN1\Type\Primitive\BitString  | 
            ||
| 157 | */  | 
            ||
| 158 | 2 | public function asBitString(): Primitive\BitString  | 
            |
| 166 | |||
| 167 | /**  | 
            ||
| 168 | * Get the wrapped element as an octet string type.  | 
            ||
| 169 | *  | 
            ||
| 170 | * @throws \UnexpectedValueException If the element is not an octet string  | 
            ||
| 171 | * @return \ASN1\Type\Primitive\OctetString  | 
            ||
| 172 | */  | 
            ||
| 173 | 2 | public function asOctetString(): Primitive\OctetString  | 
            |
| 181 | |||
| 182 | /**  | 
            ||
| 183 | * Get the wrapped element as a null type.  | 
            ||
| 184 | *  | 
            ||
| 185 | * @throws \UnexpectedValueException If the element is not a null  | 
            ||
| 186 | * @return \ASN1\Type\Primitive\NullType  | 
            ||
| 187 | */  | 
            ||
| 188 | 10 | public function asNull(): Primitive\NullType  | 
            |
| 196 | |||
| 197 | /**  | 
            ||
| 198 | * Get the wrapped element as an object identifier type.  | 
            ||
| 199 | *  | 
            ||
| 200 | * @throws \UnexpectedValueException If the element is not an object  | 
            ||
| 201 | * identifier  | 
            ||
| 202 | * @return \ASN1\Type\Primitive\ObjectIdentifier  | 
            ||
| 203 | */  | 
            ||
| 204 | 2 | public function asObjectIdentifier(): Primitive\ObjectIdentifier  | 
            |
| 213 | |||
| 214 | /**  | 
            ||
| 215 | * Get the wrapped element as an object descriptor type.  | 
            ||
| 216 | *  | 
            ||
| 217 | * @throws \UnexpectedValueException If the element is not an object  | 
            ||
| 218 | * descriptor  | 
            ||
| 219 | * @return \ASN1\Type\Primitive\ObjectDescriptor  | 
            ||
| 220 | */  | 
            ||
| 221 | 2 | public function asObjectDescriptor(): Primitive\ObjectDescriptor  | 
            |
| 230 | |||
| 231 | /**  | 
            ||
| 232 | * Get the wrapped element as a real type.  | 
            ||
| 233 | *  | 
            ||
| 234 | * @throws \UnexpectedValueException If the element is not a real  | 
            ||
| 235 | * @return \ASN1\Type\Primitive\Real  | 
            ||
| 236 | */  | 
            ||
| 237 | 2 | public function asReal(): Primitive\Real  | 
            |
| 245 | |||
| 246 | /**  | 
            ||
| 247 | * Get the wrapped element as an enumerated type.  | 
            ||
| 248 | *  | 
            ||
| 249 | * @throws \UnexpectedValueException If the element is not an enumerated  | 
            ||
| 250 | * @return \ASN1\Type\Primitive\Enumerated  | 
            ||
| 251 | */  | 
            ||
| 252 | 2 | public function asEnumerated(): Primitive\Enumerated  | 
            |
| 260 | |||
| 261 | /**  | 
            ||
| 262 | * Get the wrapped element as a UTF8 string type.  | 
            ||
| 263 | *  | 
            ||
| 264 | * @throws \UnexpectedValueException If the element is not a UTF8 string  | 
            ||
| 265 | * @return \ASN1\Type\Primitive\UTF8String  | 
            ||
| 266 | */  | 
            ||
| 267 | 2 | public function asUTF8String(): Primitive\UTF8String  | 
            |
| 275 | |||
| 276 | /**  | 
            ||
| 277 | * Get the wrapped element as a relative OID type.  | 
            ||
| 278 | *  | 
            ||
| 279 | * @throws \UnexpectedValueException If the element is not a relative OID  | 
            ||
| 280 | * @return \ASN1\Type\Primitive\RelativeOID  | 
            ||
| 281 | */  | 
            ||
| 282 | 2 | public function asRelativeOID(): Primitive\RelativeOID  | 
            |
| 290 | |||
| 291 | /**  | 
            ||
| 292 | * Get the wrapped element as a sequence type.  | 
            ||
| 293 | *  | 
            ||
| 294 | * @throws \UnexpectedValueException If the element is not a sequence  | 
            ||
| 295 | * @return \ASN1\Type\Constructed\Sequence  | 
            ||
| 296 | */  | 
            ||
| 297 | 2 | public function asSequence(): Constructed\Sequence  | 
            |
| 305 | |||
| 306 | /**  | 
            ||
| 307 | * Get the wrapped element as a set type.  | 
            ||
| 308 | *  | 
            ||
| 309 | * @throws \UnexpectedValueException If the element is not a set  | 
            ||
| 310 | * @return \ASN1\Type\Constructed\Set  | 
            ||
| 311 | */  | 
            ||
| 312 | 2 | public function asSet(): Constructed\Set  | 
            |
| 320 | |||
| 321 | /**  | 
            ||
| 322 | * Get the wrapped element as a numeric string type.  | 
            ||
| 323 | *  | 
            ||
| 324 | * @throws \UnexpectedValueException If the element is not a numeric string  | 
            ||
| 325 | * @return \ASN1\Type\Primitive\NumericString  | 
            ||
| 326 | */  | 
            ||
| 327 | 2 | public function asNumericString(): Primitive\NumericString  | 
            |
| 335 | |||
| 336 | /**  | 
            ||
| 337 | * Get the wrapped element as a printable string type.  | 
            ||
| 338 | *  | 
            ||
| 339 | * @throws \UnexpectedValueException If the element is not a printable  | 
            ||
| 340 | * string  | 
            ||
| 341 | * @return \ASN1\Type\Primitive\PrintableString  | 
            ||
| 342 | */  | 
            ||
| 343 | 2 | public function asPrintableString(): Primitive\PrintableString  | 
            |
| 351 | |||
| 352 | /**  | 
            ||
| 353 | * Get the wrapped element as a T61 string type.  | 
            ||
| 354 | *  | 
            ||
| 355 | * @throws \UnexpectedValueException If the element is not a T61 string  | 
            ||
| 356 | * @return \ASN1\Type\Primitive\T61String  | 
            ||
| 357 | */  | 
            ||
| 358 | 2 | public function asT61String(): Primitive\T61String  | 
            |
| 366 | |||
| 367 | /**  | 
            ||
| 368 | * Get the wrapped element as a videotex string type.  | 
            ||
| 369 | *  | 
            ||
| 370 | * @throws \UnexpectedValueException If the element is not a videotex string  | 
            ||
| 371 | * @return \ASN1\Type\Primitive\VideotexString  | 
            ||
| 372 | */  | 
            ||
| 373 | 2 | public function asVideotexString(): Primitive\VideotexString  | 
            |
| 381 | |||
| 382 | /**  | 
            ||
| 383 | * Get the wrapped element as a IA5 string type.  | 
            ||
| 384 | *  | 
            ||
| 385 | * @throws \UnexpectedValueException If the element is not a IA5 string  | 
            ||
| 386 | * @return \ASN1\Type\Primitive\IA5String  | 
            ||
| 387 | */  | 
            ||
| 388 | 2 | public function asIA5String(): Primitive\IA5String  | 
            |
| 396 | |||
| 397 | /**  | 
            ||
| 398 | * Get the wrapped element as an UTC time type.  | 
            ||
| 399 | *  | 
            ||
| 400 | * @throws \UnexpectedValueException If the element is not a UTC time  | 
            ||
| 401 | * @return \ASN1\Type\Primitive\UTCTime  | 
            ||
| 402 | */  | 
            ||
| 403 | 2 | public function asUTCTime(): Primitive\UTCTime  | 
            |
| 411 | |||
| 412 | /**  | 
            ||
| 413 | * Get the wrapped element as a generalized time type.  | 
            ||
| 414 | *  | 
            ||
| 415 | * @throws \UnexpectedValueException If the element is not a generalized  | 
            ||
| 416 | * time  | 
            ||
| 417 | * @return \ASN1\Type\Primitive\GeneralizedTime  | 
            ||
| 418 | */  | 
            ||
| 419 | 2 | public function asGeneralizedTime(): Primitive\GeneralizedTime  | 
            |
| 427 | |||
| 428 | /**  | 
            ||
| 429 | * Get the wrapped element as a graphic string type.  | 
            ||
| 430 | *  | 
            ||
| 431 | * @throws \UnexpectedValueException If the element is not a graphic string  | 
            ||
| 432 | * @return \ASN1\Type\Primitive\GraphicString  | 
            ||
| 433 | */  | 
            ||
| 434 | 2 | public function asGraphicString(): Primitive\GraphicString  | 
            |
| 442 | |||
| 443 | /**  | 
            ||
| 444 | * Get the wrapped element as a visible string type.  | 
            ||
| 445 | *  | 
            ||
| 446 | * @throws \UnexpectedValueException If the element is not a visible string  | 
            ||
| 447 | * @return \ASN1\Type\Primitive\VisibleString  | 
            ||
| 448 | */  | 
            ||
| 449 | 2 | public function asVisibleString(): Primitive\VisibleString  | 
            |
| 457 | |||
| 458 | /**  | 
            ||
| 459 | * Get the wrapped element as a general string type.  | 
            ||
| 460 | *  | 
            ||
| 461 | * @throws \UnexpectedValueException If the element is not general string  | 
            ||
| 462 | * @return \ASN1\Type\Primitive\GeneralString  | 
            ||
| 463 | */  | 
            ||
| 464 | 2 | public function asGeneralString(): Primitive\GeneralString  | 
            |
| 472 | |||
| 473 | /**  | 
            ||
| 474 | * Get the wrapped element as a universal string type.  | 
            ||
| 475 | *  | 
            ||
| 476 | * @throws \UnexpectedValueException If the element is not a universal  | 
            ||
| 477 | * string  | 
            ||
| 478 | * @return \ASN1\Type\Primitive\UniversalString  | 
            ||
| 479 | */  | 
            ||
| 480 | 2 | public function asUniversalString(): Primitive\UniversalString  | 
            |
| 488 | |||
| 489 | /**  | 
            ||
| 490 | * Get the wrapped element as a character string type.  | 
            ||
| 491 | *  | 
            ||
| 492 | * @throws \UnexpectedValueException If the element is not a character  | 
            ||
| 493 | * string  | 
            ||
| 494 | * @return \ASN1\Type\Primitive\CharacterString  | 
            ||
| 495 | */  | 
            ||
| 496 | 2 | public function asCharacterString(): Primitive\CharacterString  | 
            |
| 504 | |||
| 505 | /**  | 
            ||
| 506 | * Get the wrapped element as a BMP string type.  | 
            ||
| 507 | *  | 
            ||
| 508 | * @throws \UnexpectedValueException If the element is not a bmp string  | 
            ||
| 509 | * @return \ASN1\Type\Primitive\BMPString  | 
            ||
| 510 | */  | 
            ||
| 511 | 2 | public function asBMPString(): Primitive\BMPString  | 
            |
| 519 | |||
| 520 | /**  | 
            ||
| 521 | * Get the wrapped element as any string type.  | 
            ||
| 522 | *  | 
            ||
| 523 | * @throws \UnexpectedValueException If the element is not a string  | 
            ||
| 524 | * @return StringType  | 
            ||
| 525 | */  | 
            ||
| 526 | 2 | public function asString(): StringType  | 
            |
| 534 | |||
| 535 | /**  | 
            ||
| 536 | * Get the wrapped element as any time type.  | 
            ||
| 537 | *  | 
            ||
| 538 | * @throws \UnexpectedValueException If the element is not a time  | 
            ||
| 539 | * @return TimeType  | 
            ||
| 540 | */  | 
            ||
| 541 | 2 | public function asTime(): TimeType  | 
            |
| 549 | |||
| 550 | /**  | 
            ||
| 551 | * Generate message for exceptions thrown by <code>as*</code> methods.  | 
            ||
| 552 | *  | 
            ||
| 553 | * @param int $tag Type tag of the expected element  | 
            ||
| 554 | * @return string  | 
            ||
| 555 | */  | 
            ||
| 556 | 29 | private function _generateExceptionMessage(int $tag): string  | 
            |
| 561 | |||
| 562 | /**  | 
            ||
| 563 | * Get textual description of the wrapped element for debugging purposes.  | 
            ||
| 564 | *  | 
            ||
| 565 | * @return string  | 
            ||
| 566 | */  | 
            ||
| 567 | 32 | private function _typeDescriptorString(): string  | 
            |
| 576 | |||
| 577 | /**  | 
            ||
| 578 | *  | 
            ||
| 579 | * @see \ASN1\Feature\Encodable::toDER()  | 
            ||
| 580 | * @return string  | 
            ||
| 581 | */  | 
            ||
| 582 | 1 | public function toDER(): string  | 
            |
| 586 | |||
| 587 | /**  | 
            ||
| 588 | *  | 
            ||
| 589 | * @see \ASN1\Feature\ElementBase::typeClass()  | 
            ||
| 590 | * @return int  | 
            ||
| 591 | */  | 
            ||
| 592 | 2 | public function typeClass(): int  | 
            |
| 596 | |||
| 597 | /**  | 
            ||
| 598 | *  | 
            ||
| 599 | * @see \ASN1\Feature\ElementBase::isConstructed()  | 
            ||
| 600 | * @return bool  | 
            ||
| 601 | */  | 
            ||
| 602 | 3 | public function isConstructed(): bool  | 
            |
| 606 | |||
| 607 | /**  | 
            ||
| 608 | *  | 
            ||
| 609 | * @see \ASN1\Feature\ElementBase::tag()  | 
            ||
| 610 | * @return int  | 
            ||
| 611 | */  | 
            ||
| 612 | 9 | public function tag(): int  | 
            |
| 616 | |||
| 617 | /**  | 
            ||
| 618 | *  | 
            ||
| 619 |      * {@inheritdoc} | 
            ||
| 620 | * @see \ASN1\Feature\ElementBase::isType()  | 
            ||
| 621 | * @return bool  | 
            ||
| 622 | */  | 
            ||
| 623 | 1 | public function isType(int $tag): bool  | 
            |
| 627 | |||
| 628 | /**  | 
            ||
| 629 | *  | 
            ||
| 630 | * @deprecated Use any <code>as*</code> accessor method first to ensure  | 
            ||
| 631 | * type strictness.  | 
            ||
| 632 | * @see \ASN1\Feature\ElementBase::expectType()  | 
            ||
| 633 | * @return ElementBase  | 
            ||
| 634 | */  | 
            ||
| 635 | 1 | public function expectType(int $tag): ElementBase  | 
            |
| 639 | |||
| 640 | /**  | 
            ||
| 641 | *  | 
            ||
| 642 | * @see \ASN1\Feature\ElementBase::isTagged()  | 
            ||
| 643 | * @return bool  | 
            ||
| 644 | */  | 
            ||
| 645 | 1 | public function isTagged(): bool  | 
            |
| 649 | |||
| 650 | /**  | 
            ||
| 651 | *  | 
            ||
| 652 | * @deprecated Use any <code>as*</code> accessor method first to ensure  | 
            ||
| 653 | * type strictness.  | 
            ||
| 654 | * @see \ASN1\Feature\ElementBase::expectTagged()  | 
            ||
| 655 | * @return TaggedType  | 
            ||
| 656 | */  | 
            ||
| 657 | 1 | public function expectTagged($tag = null): TaggedType  | 
            |
| 661 | |||
| 662 | /**  | 
            ||
| 663 | *  | 
            ||
| 664 | * @see \ASN1\Feature\ElementBase::asElement()  | 
            ||
| 665 | * @return Element  | 
            ||
| 666 | */  | 
            ||
| 667 | 1 | public function asElement(): Element  | 
            |
| 671 | |||
| 672 | /**  | 
            ||
| 673 | *  | 
            ||
| 674 |      * {@inheritdoc} | 
            ||
| 675 | * @return UnspecifiedType  | 
            ||
| 676 | */  | 
            ||
| 677 | 1 | public function asUnspecified(): UnspecifiedType  | 
            |
| 681 | }  | 
            ||
| 682 |