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