Conditions | 2 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
102 | public static function fromXML(DOMElement $xml): static |
||
103 | { |
||
104 | Assert::same($xml->localName, 'Signature', InvalidDOMElementException::class); |
||
105 | Assert::same($xml->namespaceURI, Signature::NS, InvalidDOMElementException::class); |
||
106 | |||
107 | $Id = self::getAttribute($xml, 'Id', null); |
||
108 | |||
109 | $signedInfo = SignedInfo::getChildrenOfClass($xml); |
||
110 | Assert::minCount( |
||
111 | $signedInfo, |
||
112 | 1, |
||
113 | 'ds:Signature needs exactly one ds:SignedInfo element.', |
||
114 | MissingElementException::class, |
||
115 | ); |
||
116 | Assert::maxCount( |
||
117 | $signedInfo, |
||
118 | 1, |
||
119 | 'ds:Signature needs exactly one ds:SignedInfo element.', |
||
120 | TooManyElementsException::class, |
||
121 | ); |
||
122 | |||
123 | $signatureValue = SignatureValue::getChildrenOfClass($xml); |
||
124 | Assert::minCount( |
||
125 | $signatureValue, |
||
126 | 1, |
||
127 | 'ds:Signature needs exactly one ds:SignatureValue element.', |
||
128 | MissingElementException::class, |
||
129 | ); |
||
130 | Assert::maxCount( |
||
131 | $signatureValue, |
||
132 | 1, |
||
133 | 'ds:Signature needs exactly one ds:SignatureValue element.', |
||
134 | TooManyElementsException::class, |
||
135 | ); |
||
136 | |||
137 | $keyInfo = KeyInfo::getChildrenOfClass($xml); |
||
138 | Assert::maxCount( |
||
139 | $keyInfo, |
||
140 | 1, |
||
141 | 'ds:Signature can hold a maximum of one ds:KeyInfo element.', |
||
142 | TooManyElementsException::class, |
||
143 | ); |
||
144 | |||
145 | $objects = DsObject::getChildrenOfClass($xml); |
||
146 | |||
147 | return new static( |
||
148 | array_pop($signedInfo), |
||
149 | array_pop($signatureValue), |
||
150 | empty($keyInfo) ? null : array_pop($keyInfo), |
||
151 | $objects, |
||
152 | $Id, |
||
153 | ); |
||
182 |