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