| Conditions | 2 | 
| Paths | 2 | 
| Total Lines | 67 | 
| Code Lines | 44 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | 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  | 
            ||
| 98 | public static function fromXML(DOMElement $xml): static  | 
            ||
| 99 |     { | 
            ||
| 100 | Assert::same($xml->localName, 'AuthnQuery', InvalidDOMElementException::class);  | 
            ||
| 101 | Assert::same($xml->namespaceURI, AuthnQuery::NS, InvalidDOMElementException::class);  | 
            ||
| 102 | |||
| 103 | /** @psalm-var string $version */  | 
            ||
| 104 | $version = self::getAttribute($xml, 'Version');  | 
            ||
| 105 |         Assert::true(version_compare('2.0', $version, '<='), RequestVersionTooLowException::class); | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 106 |         Assert::true(version_compare('2.0', $version, '>='), RequestVersionTooHighException::class); | 
            ||
| 107 | |||
| 108 | $id = self::getAttribute($xml, 'ID');  | 
            ||
| 109 | $destination = self::getAttribute($xml, 'Destination', null);  | 
            ||
| 110 | $consent = self::getAttribute($xml, 'Consent', null);  | 
            ||
| 111 | $sessionIndex = self::getAttribute($xml, 'SessionIndex', null);  | 
            ||
| 112 | |||
| 113 | /** @psalm-var string $issueInstant */  | 
            ||
| 114 | $issueInstant = self::getAttribute($xml, 'IssueInstant');  | 
            ||
| 115 | // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications  | 
            ||
| 116 |         $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); | 
            ||
| 117 | |||
| 118 | Assert::validDateTimeZulu($issueInstant, ProtocolViolationException::class);  | 
            ||
| 119 | $issueInstant = XMLUtils::xsDateTimeToTimestamp($issueInstant);  | 
            ||
| 120 | |||
| 121 | $requestedAuthnContext = RequestedAuthnContext::getChildrenOfClass($xml);  | 
            ||
| 122 | |||
| 123 | $issuer = Issuer::getChildrenOfClass($xml);  | 
            ||
| 124 | Assert::countBetween($issuer, 0, 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 | $subject = Subject::getChildrenOfClass($xml);  | 
            ||
| 135 | Assert::notEmpty($subject, 'Missing subject in subject query.', MissingElementException::class);  | 
            ||
| 136 | Assert::maxCount(  | 
            ||
| 137 | $subject,  | 
            ||
| 138 | 1,  | 
            ||
| 139 | 'More than one <saml:Subject> in AttributeQuery',  | 
            ||
| 140 | TooManyElementsException::class,  | 
            ||
| 141 | );  | 
            ||
| 142 | |||
| 143 | $signature = Signature::getChildrenOfClass($xml);  | 
            ||
| 144 | Assert::maxCount($signature, 1, 'Only one ds:Signature element is allowed.', TooManyElementsException::class);  | 
            ||
| 145 | |||
| 146 | $request = new static(  | 
            ||
| 147 | array_pop($subject),  | 
            ||
| 148 | array_pop($requestedAuthnContext),  | 
            ||
| 149 | $sessionIndex,  | 
            ||
| 150 | array_pop($issuer),  | 
            ||
| 151 | $id,  | 
            ||
| 152 | $version,  | 
            ||
| 153 | $issueInstant,  | 
            ||
| 154 | $destination,  | 
            ||
| 155 | $consent,  | 
            ||
| 156 | array_pop($extensions),  | 
            ||
| 157 | );  | 
            ||
| 158 | |||
| 159 |         if (!empty($signature)) { | 
            ||
| 160 | $request->setSignature($signature[0]);  | 
            ||
| 161 | $request->setXML($xml);  | 
            ||
| 162 | }  | 
            ||
| 163 | |||
| 164 | return $request;  | 
            ||
| 165 | }  | 
            ||
| 188 |