Conditions | 11 |
Paths | 11 |
Total Lines | 51 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
47 | public function parse(string $binaryData): PublicKeyInterface |
||
48 | { |
||
49 | $asnObject = ASNObject::fromBinary($binaryData); |
||
50 | if ($asnObject->getType() !== Identifier::SEQUENCE) { |
||
51 | throw new \RuntimeException('Invalid data.'); |
||
52 | } |
||
53 | |||
54 | /** @var Sequence $asnObject */ |
||
55 | if ($asnObject->getNumberofChildren() != 2) { |
||
56 | throw new \RuntimeException('Invalid data.'); |
||
57 | } |
||
58 | |||
59 | $children = $asnObject->getChildren(); |
||
60 | if (count($children) != 2) { |
||
61 | throw new \RuntimeException('Invalid data.'); |
||
62 | } |
||
63 | |||
64 | if (count($children) != 2) { |
||
65 | throw new \RuntimeException('Invalid data.'); |
||
66 | } |
||
67 | |||
68 | if ($children[0]->getType() !== Identifier::SEQUENCE) { |
||
69 | throw new \RuntimeException('Invalid data.'); |
||
70 | } |
||
71 | |||
72 | if (count($children[0]->getChildren()) != 2) { |
||
|
|||
73 | throw new \RuntimeException('Invalid data.'); |
||
74 | } |
||
75 | |||
76 | if ($children[0]->getChildren()[0]->getType() !== Identifier::OBJECT_IDENTIFIER) { |
||
77 | throw new \RuntimeException('Invalid data.'); |
||
78 | } |
||
79 | |||
80 | if ($children[0]->getChildren()[1]->getType() !== Identifier::OBJECT_IDENTIFIER) { |
||
81 | throw new \RuntimeException('Invalid data.'); |
||
82 | } |
||
83 | |||
84 | if ($children[1]->getType() !== Identifier::BITSTRING) { |
||
85 | throw new \RuntimeException('Invalid data.'); |
||
86 | } |
||
87 | |||
88 | $oid = $children[0]->getChildren()[0]; |
||
89 | $curveOid = $children[0]->getChildren()[1]; |
||
90 | $encodedKey = $children[1]; |
||
91 | if ($oid->getContent() !== DerPublicKeySerializer::X509_ECDSA_OID) { |
||
92 | throw new \RuntimeException('Invalid data: non X509 data.'); |
||
93 | } |
||
94 | |||
95 | $generator = CurveOidMapper::getGeneratorFromOid($curveOid); |
||
96 | |||
97 | return $this->parseKey($generator, $encodedKey->getContent()); |
||
98 | } |
||
112 |