| Conditions | 2 | 
| Paths | 2 | 
| Total Lines | 61 | 
| Code Lines | 40 | 
| 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 | ||
| 85 | public static function fromXML(DOMElement $xml): static | ||
| 86 |     { | ||
| 87 | Assert::same($xml->localName, 'AssertionIDRequest', InvalidDOMElementException::class); | ||
| 88 | Assert::same($xml->namespaceURI, AssertionIDRequest::NS, InvalidDOMElementException::class); | ||
| 89 | |||
| 90 | $assertionIDRef = AssertionIDRef::getChildrenOfClass($xml); | ||
| 91 | Assert::minCount( | ||
| 92 | $assertionIDRef, | ||
| 93 | 1, | ||
| 94 | 'At least one <samlp:AssertionIDRef> element is required.', | ||
| 95 | TooManyElementsException::class, | ||
| 96 | ); | ||
| 97 | |||
| 98 | $issuer = Issuer::getChildrenOfClass($xml); | ||
| 99 | Assert::maxCount($issuer, 1, 'Only one <saml:Issuer> element is allowed.', TooManyElementsException::class); | ||
| 100 | |||
| 101 | $version = self::getAttribute($xml, 'Version'); | ||
| 102 |         Assert::true(version_compare('2.0', $version, '<='), RequestVersionTooLowException::class); | ||
| 103 |         Assert::true(version_compare('2.0', $version, '>='), RequestVersionTooHighException::class); | ||
| 104 | |||
| 105 | $issueInstant = self::getAttribute($xml, 'IssueInstant'); | ||
| 106 | // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications | ||
| 107 |         $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); | ||
| 108 | |||
| 109 | Assert::validDateTimeZulu($issueInstant, ProtocolViolationException::class); | ||
| 110 | $issueInstant = XMLUtils::xsDateTimeToTimestamp($issueInstant); | ||
| 111 | |||
| 112 | $extensions = Extensions::getChildrenOfClass($xml); | ||
| 113 | Assert::maxCount( | ||
| 114 | $extensions, | ||
| 115 | 1, | ||
| 116 | 'Only one <samlp:Extensions> element is allowed.', | ||
| 117 | TooManyElementsException::class, | ||
| 118 | ); | ||
| 119 | |||
| 120 | $signature = Signature::getChildrenOfClass($xml); | ||
| 121 | Assert::maxCount( | ||
| 122 | $signature, | ||
| 123 | 1, | ||
| 124 | 'Only one <ds:Signature> element is allowed.', | ||
| 125 | TooManyElementsException::class, | ||
| 126 | ); | ||
| 127 | |||
| 128 | $request = new static( | ||
| 129 | $assertionIDRef, | ||
| 130 | array_pop($issuer), | ||
| 131 | self::getAttribute($xml, 'ID'), | ||
| 132 | $version, | ||
| 133 | $issueInstant, | ||
| 134 | self::getAttribute($xml, 'Destination', null), | ||
| 135 | self::getAttribute($xml, 'Consent', null), | ||
| 136 | array_pop($extensions), | ||
| 137 | ); | ||
| 138 | |||
| 139 |         if (!empty($signature)) { | ||
| 140 | $request->setSignature($signature[0]); | ||
| 141 | $request->messageContainedSignatureUponConstruction = true; | ||
| 142 | $request->setXML($xml); | ||
| 143 | } | ||
| 144 | |||
| 145 | return $request; | ||
| 146 | } | ||
| 166 |