| Conditions | 6 |
| Paths | 6 |
| Total Lines | 63 |
| Code Lines | 40 |
| 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 |
||
| 97 | public static function fromXML(DOMElement $xml): static |
||
| 98 | { |
||
| 99 | Assert::same($xml->localName, 'ArtifactResponse', InvalidDOMElementException::class); |
||
| 100 | Assert::same($xml->namespaceURI, ArtifactResponse::NS, InvalidDOMElementException::class); |
||
| 101 | |||
| 102 | $version = self::getAttribute($xml, 'Version', SAMLStringValue::class); |
||
| 103 | Assert::true(version_compare('2.0', $version->getValue(), '<='), RequestVersionTooLowException::class); |
||
| 104 | Assert::true(version_compare('2.0', $version->getValue(), '>='), RequestVersionTooHighException::class); |
||
| 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 = XPath::xpQuery($xml, './saml_protocol:Status', XPath::getXPath($xml)); |
||
| 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( |
||
| 128 | $extensions, |
||
| 129 | 1, |
||
| 130 | 'Only one saml:Extensions element is allowed.', |
||
| 131 | TooManyElementsException::class, |
||
| 132 | ); |
||
| 133 | |||
| 134 | $signature = Signature::getChildrenOfClass($xml); |
||
| 135 | Assert::maxCount( |
||
| 136 | $signature, |
||
| 137 | 1, |
||
| 138 | 'Only one ds:Signature element is allowed.', |
||
| 139 | TooManyElementsException::class, |
||
| 140 | ); |
||
| 141 | |||
| 142 | $response = new static( |
||
| 143 | self::getAttribute($xml, 'ID', IDValue::class), |
||
| 144 | array_pop($status), |
||
| 145 | self::getAttribute($xml, 'IssueInstant', SAMLDateTimeValue::class), |
||
| 146 | empty($issuer) ? null : array_pop($issuer), |
||
| 147 | self::getOptionalAttribute($xml, 'InResponseTo', NCNameValue::class, null), |
||
| 148 | self::getOptionalAttribute($xml, 'Destination', SAMLAnyURIValue::class, null), |
||
| 149 | self::getOptionalAttribute($xml, 'Consent', SAMLAnyURIValue::class, null), |
||
| 150 | empty($extensions) ? null : array_pop($extensions), |
||
| 151 | $message, |
||
| 152 | ); |
||
| 153 | |||
| 154 | if (!empty($signature)) { |
||
| 155 | $response->setSignature($signature[0]); |
||
| 156 | $response->setXML($xml); |
||
| 157 | } |
||
| 158 | |||
| 159 | return $response; |
||
| 160 | } |
||
| 178 |