| Conditions | 7 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 39 |
| 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 |
||
| 41 | public static function fromXML(DOMElement $xml): static |
||
| 42 | { |
||
| 43 | Assert::same($xml->localName, 'Request', InvalidDOMElementException::class); |
||
| 44 | Assert::same($xml->namespaceURI, Request::NS, InvalidDOMElementException::class); |
||
| 45 | |||
| 46 | $query = AbstractQuery::getChildrenOfClass($xml); |
||
| 47 | Assert::maxCount($query, 1, TooManyElementsException::class); |
||
| 48 | |||
| 49 | $subjectQuery = AbstractSubjectQuery::getChildrenOfClass($xml); |
||
| 50 | Assert::maxCount($subjectQuery, 1, TooManyElementsException::class); |
||
| 51 | |||
| 52 | $authenticationQuery = AuthenticationQuery::getChildrenOfClass($xml); |
||
| 53 | Assert::maxCount($authenticationQuery, 1, TooManyElementsException::class); |
||
| 54 | |||
| 55 | $attributeQuery = AttributeQuery::getChildrenOfClass($xml); |
||
| 56 | Assert::maxCount($attributeQuery, 1, TooManyElementsException::class); |
||
| 57 | |||
| 58 | $authorizationDecisionQuery = AuthorizationDecisionQuery::getChildrenOfClass($xml); |
||
| 59 | Assert::maxCount($authorizationDecisionQuery, 1, TooManyElementsException::class); |
||
| 60 | |||
| 61 | $query = array_merge( |
||
| 62 | $query, |
||
| 63 | $subjectQuery, |
||
| 64 | $authenticationQuery, |
||
| 65 | $attributeQuery, |
||
| 66 | $authorizationDecisionQuery, |
||
| 67 | ); |
||
| 68 | Assert::maxCount($query, 1, TooManyElementsException::class); |
||
| 69 | |||
| 70 | $assertionIdReference = AssertionIDReference::getChildrenOfClass($xml); |
||
| 71 | $assertionArtifact = AssertionArtifact::getChildrenOfClass($xml); |
||
| 72 | |||
| 73 | Assert::true( |
||
| 74 | !empty($query) || !empty($assertionIdReference) || !empty($assertionArtifact), |
||
| 75 | TooManyElementsException::class, |
||
| 76 | ); |
||
| 77 | Assert::false( |
||
| 78 | empty($query) && empty($assertionIdReference) && empty($assertionArtifact), |
||
| 79 | MissingElementException::class, |
||
| 80 | ); |
||
| 81 | |||
| 82 | $majorVersion = self::getAttribute($xml, 'MajorVersion', NonNegativeIntegerValue::class); |
||
| 83 | Assert::same($majorVersion->getValue(), '1', VersionMismatchException::class); |
||
| 84 | |||
| 85 | $minorVersion = self::getAttribute($xml, 'MinorVersion', NonNegativeIntegerValue::class); |
||
| 86 | Assert::same($minorVersion->getValue(), '1', VersionMismatchException::class); |
||
| 87 | |||
| 88 | $issueInstant = self::getAttribute($xml, 'IssueInstant', SAMLDateTimeValue::class); |
||
| 89 | |||
| 90 | return new static( |
||
| 91 | $assertionIdReference ?: $assertionArtifact ?: array_pop($query), |
||
| 92 | self::getAttribute($xml, 'RequestID', IDValue::class), |
||
| 93 | $majorVersion, |
||
| 94 | $minorVersion, |
||
| 95 | $issueInstant, |
||
| 96 | RespondWith::getChildrenOfClass($xml), |
||
| 97 | ); |
||
| 100 |