Conditions | 2 |
Paths | 2 |
Total Lines | 61 |
Code Lines | 41 |
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 |
||
113 | public static function fromXML(DOMElement $xml): static |
||
114 | { |
||
115 | Assert::same($xml->localName, 'AttributeQuery', InvalidDOMElementException::class); |
||
116 | Assert::same($xml->namespaceURI, AttributeQuery::NS, InvalidDOMElementException::class); |
||
117 | |||
118 | $version = self::getAttribute($xml, 'Version'); |
||
119 | Assert::true(version_compare('2.0', $version, '<='), RequestVersionTooLowException::class); |
||
120 | Assert::true(version_compare('2.0', $version, '>='), RequestVersionTooHighException::class); |
||
121 | |||
122 | $id = self::getAttribute($xml, 'ID'); |
||
123 | $destination = self::getAttribute($xml, 'Destination', null); |
||
124 | $consent = self::getAttribute($xml, 'Consent', null); |
||
125 | |||
126 | $issueInstant = self::getAttribute($xml, 'IssueInstant'); |
||
127 | // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications |
||
128 | $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); |
||
129 | |||
130 | Assert::validDateTimeZulu($issueInstant, ProtocolViolationException::class); |
||
131 | $issueInstant = XMLUtils::xsDateTimeToTimestamp($issueInstant); |
||
132 | |||
133 | $issuer = Issuer::getChildrenOfClass($xml); |
||
134 | Assert::countBetween($issuer, 0, 1); |
||
135 | |||
136 | $extensions = Extensions::getChildrenOfClass($xml); |
||
137 | Assert::maxCount( |
||
138 | $extensions, |
||
139 | 1, |
||
140 | 'Only one saml:Extensions element is allowed.', |
||
141 | TooManyElementsException::class, |
||
142 | ); |
||
143 | |||
144 | $subject = Subject::getChildrenOfClass($xml); |
||
145 | Assert::notEmpty($subject, 'Missing subject in subject query.', MissingElementException::class); |
||
146 | Assert::maxCount( |
||
147 | $subject, |
||
148 | 1, |
||
149 | 'More than one <saml:Subject> in AttributeQuery', |
||
150 | TooManyElementsException::class, |
||
151 | ); |
||
152 | |||
153 | $signature = Signature::getChildrenOfClass($xml); |
||
154 | Assert::maxCount($signature, 1, 'Only one ds:Signature element is allowed.', TooManyElementsException::class); |
||
155 | |||
156 | $request = new static( |
||
157 | array_pop($subject), |
||
158 | Attribute::getChildrenOfClass($xml), |
||
159 | array_pop($issuer), |
||
160 | $id, |
||
161 | $version, |
||
162 | $issueInstant, |
||
163 | $destination, |
||
164 | $consent, |
||
165 | array_pop($extensions), |
||
166 | ); |
||
167 | |||
168 | if (!empty($signature)) { |
||
169 | $request->setSignature($signature[0]); |
||
170 | $request->setXML($xml); |
||
171 | } |
||
172 | |||
173 | return $request; |
||
174 | } |
||
194 |