Conditions | 6 |
Paths | 6 |
Total Lines | 55 |
Code Lines | 36 |
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 |
||
94 | public static function fromXML(DOMElement $xml): object |
||
95 | { |
||
96 | Assert::same($xml->localName, 'ArtifactResponse'); |
||
97 | Assert::same($xml->namespaceURI, ArtifactResponse::NS); |
||
98 | Assert::same('2.0', self::getAttribute($xml, 'Version')); |
||
99 | |||
100 | $id = self::getAttribute($xml, 'ID'); |
||
101 | $issueInstant = Utils::xsDateTimeToTimestamp(self::getAttribute($xml, 'IssueInstant')); |
||
102 | $inResponseTo = self::getAttribute($xml, 'InResponseTo', null); |
||
103 | $destination = self::getAttribute($xml, 'Destination', null); |
||
104 | $consent = self::getAttribute($xml, 'Consent', null); |
||
105 | |||
106 | $issuer = Issuer::getChildrenOfClass($xml); |
||
107 | Assert::countBetween($issuer, 0, 1); |
||
108 | |||
109 | // find message; it should come last, after the Status-element |
||
110 | $status = Utils::xpQuery($xml, './saml_protocol:Status'); |
||
111 | $status = $status[0]; |
||
112 | $message = null; |
||
113 | |||
114 | /** @psalm-suppress RedundantCondition */ |
||
115 | for ($child = $status->nextSibling; $child !== null; $child = $child->nextSibling) { |
||
116 | if ($child instanceof DOMElement) { |
||
117 | $message = MessageFactory::fromXML($child); |
||
118 | break; |
||
119 | } |
||
120 | /* Ignore comments and text nodes. */ |
||
121 | } |
||
122 | |||
123 | $status = Status::getChildrenOfClass($xml); |
||
124 | Assert::count($status, 1); |
||
125 | |||
126 | $extensions = Extensions::getChildrenOfClass($xml); |
||
127 | Assert::maxCount($extensions, 1, 'Only one saml:Extensions element is allowed.'); |
||
128 | |||
129 | $signature = Signature::getChildrenOfClass($xml); |
||
130 | Assert::maxCount($signature, 1, 'Only one ds:Signature element is allowed.'); |
||
131 | |||
132 | $response = new self( |
||
133 | array_pop($status), |
||
134 | empty($issuer) ? null : array_pop($issuer), |
||
135 | $id, |
||
136 | $issueInstant, |
||
137 | $inResponseTo, |
||
138 | $destination, |
||
139 | $consent, |
||
140 | empty($extensions) ? null : array_pop($extensions), |
||
141 | $message |
||
142 | ); |
||
143 | |||
144 | if (!empty($signature)) { |
||
145 | $response->setSignature($signature[0]); |
||
146 | } |
||
147 | |||
148 | return $response; |
||
149 | } |
||
168 |