| Conditions | 9 |
| Paths | 12 |
| Total Lines | 58 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 100 | public static function fromXML(DOMElement $xml): object |
||
| 101 | { |
||
| 102 | Assert::same($xml->localName, 'Response'); |
||
| 103 | Assert::same($xml->namespaceURI, Response::NS); |
||
| 104 | Assert::same('2.0', self::getAttribute($xml, 'Version')); |
||
| 105 | |||
| 106 | $id = self::getAttribute($xml, 'ID'); |
||
| 107 | /** @psalm-suppress PossiblyNullArgument */ |
||
| 108 | $issueInstant = Utils::xsDateTimeToTimestamp(self::getAttribute($xml, 'IssueInstant')); |
||
| 109 | $inResponseTo = self::getAttribute($xml, 'InResponseTo', null); |
||
| 110 | $destination = self::getAttribute($xml, 'Destination', null); |
||
| 111 | $consent = self::getAttribute($xml, 'Consent', null); |
||
| 112 | |||
| 113 | $issuer = Issuer::getChildrenOfClass($xml); |
||
| 114 | Assert::countBetween($issuer, 0, 1); |
||
| 115 | |||
| 116 | $status = Status::getChildrenOfClass($xml); |
||
| 117 | Assert::count($status, 1); |
||
| 118 | |||
| 119 | $extensions = Extensions::getChildrenOfClass($xml); |
||
| 120 | Assert::maxCount($extensions, 1, 'Only one saml:Extensions element is allowed.'); |
||
| 121 | |||
| 122 | $assertions = []; |
||
| 123 | foreach ($xml->childNodes as $node) { |
||
| 124 | if ($node->namespaceURI !== Constants::NS_SAML) { |
||
| 125 | continue; |
||
| 126 | } elseif (!($node instanceof DOMElement)) { |
||
| 127 | continue; |
||
| 128 | } |
||
| 129 | |||
| 130 | if ($node->localName === 'Assertion') { |
||
| 131 | $assertions[] = new Assertion($node); |
||
| 132 | } elseif ($node->localName === 'EncryptedAssertion') { |
||
| 133 | $assertions[] = EncryptedAssertion::fromXML($node); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | $signature = Signature::getChildrenOfClass($xml); |
||
| 138 | Assert::maxCount($signature, 1, 'Only one ds:Signature element is allowed.'); |
||
| 139 | |||
| 140 | $response = new self( |
||
| 141 | array_pop($status), |
||
| 142 | empty($issuer) ? null : array_pop($issuer), |
||
| 143 | $id, |
||
| 144 | $issueInstant, |
||
| 145 | $inResponseTo, |
||
| 146 | $destination, |
||
| 147 | $consent, |
||
| 148 | empty($extensions) ? null : array_pop($extensions), |
||
| 149 | $assertions |
||
| 150 | ); |
||
| 151 | |||
| 152 | if (!empty($signature)) { |
||
| 153 | $response->setSignature($signature[0]); |
||
| 154 | $response->messageContainedSignatureUponConstruction = true; |
||
| 155 | } |
||
| 156 | |||
| 157 | return $response; |
||
| 158 | } |
||
| 177 |