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