| Conditions | 5 |
| Paths | 8 |
| Total Lines | 59 |
| Code Lines | 41 |
| 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 |
||
| 108 | public static function fromXML(DOMElement $xml): static |
||
| 109 | { |
||
| 110 | Assert::same($xml->localName, 'RoleDescriptor', InvalidDOMElementException::class); |
||
| 111 | Assert::same($xml->namespaceURI, C::NS_MD, InvalidDOMElementException::class); |
||
| 112 | Assert::true( |
||
| 113 | $xml->hasAttributeNS(C::NS_XSI, 'type'), |
||
| 114 | 'Missing required xsi:type in <saml:RoleDescriptor> element.', |
||
| 115 | SchemaViolationException::class |
||
| 116 | ); |
||
| 117 | |||
| 118 | $type = $xml->getAttributeNS(C::NS_XSI, 'type'); |
||
| 119 | Assert::validQName($type, SchemaViolationException::class); |
||
| 120 | |||
| 121 | // first, try to resolve the type to a full namespaced version |
||
| 122 | $qname = explode(':', $type, 2); |
||
| 123 | if (count($qname) === 2) { |
||
| 124 | list($prefix, $element) = $qname; |
||
| 125 | } else { |
||
| 126 | $prefix = null; |
||
| 127 | list($element) = $qname; |
||
| 128 | } |
||
| 129 | $ns = $xml->lookupNamespaceUri($prefix); |
||
| 130 | $type = ($ns === null ) ? $element : implode(':', [$ns, $element]); |
||
| 131 | |||
| 132 | // now check if we have a handler registered for it |
||
| 133 | $handler = Utils::getContainer()->getExtensionHandler($type); |
||
| 134 | if ($handler === null) { |
||
| 135 | // we don't have a handler, proceed with unknown RoleDescriptor |
||
| 136 | $protocols = self::getAttribute($xml, 'protocolSupportEnumeration'); |
||
| 137 | |||
| 138 | $validUntil = self::getAttribute($xml, 'validUntil', null); |
||
| 139 | $orgs = Organization::getChildrenOfClass($xml); |
||
| 140 | Assert::maxCount($orgs, 1, 'More than one Organization found in this descriptor', TooManyElementsException::class); |
||
| 141 | |||
| 142 | $extensions = Extensions::getChildrenOfClass($xml); |
||
| 143 | Assert::maxCount($extensions, 1, 'Only one md:Extensions element is allowed.', TooManyElementsException::class); |
||
| 144 | |||
| 145 | return new UnknownRoleDescriptor( |
||
| 146 | new Chunk($xml), |
||
| 147 | $type, |
||
| 148 | preg_split('/[\s]+/', trim($protocols)), |
||
| 149 | self::getAttribute($xml, 'ID', null), |
||
| 150 | $validUntil !== null ? XMLUtils::xsDateTimeToTimestamp($validUntil) : null, |
||
| 151 | self::getAttribute($xml, 'cacheDuration', null), |
||
| 152 | array_pop($extensions), |
||
| 153 | self::getAttribute($xml, 'errorURL', null), |
||
| 154 | KeyDescriptor::getChildrenOfClass($xml), |
||
| 155 | array_pop($orgs), |
||
| 156 | ContactPerson::getChildrenOfClass($xml), |
||
| 157 | ); |
||
| 158 | } |
||
| 159 | |||
| 160 | Assert::subclassOf( |
||
| 161 | $handler, |
||
| 162 | AbstractRoleDescriptor::class, |
||
| 163 | 'Elements implementing RoleDescriptor must extend \SimpleSAML\SAML2\XML\saml\AbstractRoleDescriptor.', |
||
| 164 | ); |
||
| 165 | |||
| 166 | return $handler::fromXML($xml); |
||
| 167 | } |
||
| 189 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.