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 |
||
107 | public static function fromXML(DOMElement $xml): static |
||
108 | { |
||
109 | Assert::same($xml->localName, 'Signature', InvalidDOMElementException::class); |
||
110 | Assert::same($xml->namespaceURI, Signature::NS, InvalidDOMElementException::class); |
||
111 | |||
112 | $Id = self::getOptionalAttribute($xml, 'Id', null); |
||
113 | |||
114 | $signedInfo = SignedInfo::getChildrenOfClass($xml); |
||
115 | Assert::minCount( |
||
116 | $signedInfo, |
||
117 | 1, |
||
118 | 'ds:Signature needs exactly one ds:SignedInfo element.', |
||
119 | MissingElementException::class, |
||
120 | ); |
||
121 | Assert::maxCount( |
||
122 | $signedInfo, |
||
123 | 1, |
||
124 | 'ds:Signature needs exactly one ds:SignedInfo element.', |
||
125 | TooManyElementsException::class, |
||
126 | ); |
||
127 | |||
128 | $signatureValue = SignatureValue::getChildrenOfClass($xml); |
||
129 | Assert::minCount( |
||
130 | $signatureValue, |
||
131 | 1, |
||
132 | 'ds:Signature needs exactly one ds:SignatureValue element.', |
||
133 | MissingElementException::class, |
||
134 | ); |
||
135 | Assert::maxCount( |
||
136 | $signatureValue, |
||
137 | 1, |
||
138 | 'ds:Signature needs exactly one ds:SignatureValue element.', |
||
139 | TooManyElementsException::class, |
||
140 | ); |
||
141 | |||
142 | $keyInfo = KeyInfo::getChildrenOfClass($xml); |
||
143 | Assert::maxCount( |
||
144 | $keyInfo, |
||
145 | 1, |
||
146 | 'ds:Signature can hold a maximum of one ds:KeyInfo element.', |
||
147 | TooManyElementsException::class, |
||
148 | ); |
||
149 | |||
150 | $objects = DsObject::getChildrenOfClass($xml); |
||
151 | |||
152 | return new static( |
||
153 | array_pop($signedInfo), |
||
154 | array_pop($signatureValue), |
||
155 | empty($keyInfo) ? null : array_pop($keyInfo), |
||
156 | $objects, |
||
157 | $Id, |
||
158 | ); |
||
187 |