| Conditions | 7 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 42 |
| 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 |
||
| 42 | public static function fromXML(DOMElement $xml): static |
||
| 43 | { |
||
| 44 | Assert::same($xml->localName, 'Request', InvalidDOMElementException::class); |
||
| 45 | Assert::same($xml->namespaceURI, Request::NS, InvalidDOMElementException::class); |
||
| 46 | |||
| 47 | $query = AbstractQuery::getChildrenOfClass($xml); |
||
| 48 | Assert::maxCount($query, 1, TooManyElementsException::class); |
||
| 49 | |||
| 50 | $subjectQuery = AbstractSubjectQuery::getChildrenOfClass($xml); |
||
| 51 | Assert::maxCount($subjectQuery, 1, TooManyElementsException::class); |
||
| 52 | |||
| 53 | $authenticationQuery = AuthenticationQuery::getChildrenOfClass($xml); |
||
| 54 | Assert::maxCount($authenticationQuery, 1, TooManyElementsException::class); |
||
| 55 | |||
| 56 | $attributeQuery = AttributeQuery::getChildrenOfClass($xml); |
||
| 57 | Assert::maxCount($attributeQuery, 1, TooManyElementsException::class); |
||
| 58 | |||
| 59 | $authorizationDecisionQuery = AuthorizationDecisionQuery::getChildrenOfClass($xml); |
||
| 60 | Assert::maxCount($authorizationDecisionQuery, 1, TooManyElementsException::class); |
||
| 61 | |||
| 62 | $query = array_merge( |
||
| 63 | $query, |
||
| 64 | $subjectQuery, |
||
| 65 | $authenticationQuery, |
||
| 66 | $attributeQuery, |
||
| 67 | $authorizationDecisionQuery, |
||
| 68 | ); |
||
| 69 | Assert::maxCount($query, 1, TooManyElementsException::class); |
||
| 70 | |||
| 71 | $assertionIdReference = AssertionIDReference::getChildrenOfClass($xml); |
||
| 72 | $assertionArtifact = AssertionArtifact::getChildrenOfClass($xml); |
||
| 73 | |||
| 74 | Assert::true( |
||
| 75 | !empty($query) || !empty($assertionIdReference) || !empty($assertionArtifact), |
||
| 76 | TooManyElementsException::class, |
||
| 77 | ); |
||
| 78 | Assert::false( |
||
| 79 | empty($query) && empty($assertionIdReference) && empty($assertionArtifact), |
||
| 80 | MissingElementException::class, |
||
| 81 | ); |
||
| 82 | |||
| 83 | $majorVersion = self::getIntegerAttribute($xml, 'MajorVersion'); |
||
| 84 | Assert::same($majorVersion, 1, VersionMismatchException::class); |
||
| 85 | |||
| 86 | $minorVersion = self::getIntegerAttribute($xml, 'MinorVersion'); |
||
| 87 | Assert::same($minorVersion, 1, VersionMismatchException::class); |
||
| 88 | |||
| 89 | $issueInstant = self::getAttribute($xml, 'IssueInstant'); |
||
| 90 | // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications |
||
| 91 | $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); |
||
| 92 | |||
| 93 | SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); |
||
| 94 | $issueInstant = new DateTimeImmutable($issueInstant); |
||
| 95 | |||
| 96 | return new static( |
||
| 97 | $assertionIdReference ?: $assertionArtifact ?: array_pop($query), |
||
| 98 | self::getAttribute($xml, 'RequestID'), |
||
| 99 | $majorVersion, |
||
| 100 | $minorVersion, |
||
| 101 | $issueInstant, |
||
| 102 | RespondWith::getChildrenOfClass($xml), |
||
| 103 | ); |
||
| 106 |