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