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