Conditions | 7 |
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 |
||
103 | public static function fromXML(DOMElement $xml): static |
||
104 | { |
||
105 | Assert::same($xml->localName, 'RoleDescriptor', InvalidDOMElementException::class); |
||
106 | Assert::same($xml->namespaceURI, C::NS_MD, InvalidDOMElementException::class); |
||
107 | Assert::true( |
||
108 | $xml->hasAttributeNS(C::NS_XSI, 'type'), |
||
109 | 'Missing required xsi:type in <saml:RoleDescriptor> element.', |
||
110 | SchemaViolationException::class |
||
111 | ); |
||
112 | |||
113 | $type = $xml->getAttributeNS(C::NS_XSI, 'type'); |
||
114 | Assert::validQName($type, SchemaViolationException::class); |
||
115 | |||
116 | // first, try to resolve the type to a full namespaced version |
||
117 | $qname = explode(':', $type, 2); |
||
118 | if (count($qname) === 2) { |
||
119 | list($prefix, $element) = $qname; |
||
120 | } else { |
||
121 | $prefix = null; |
||
122 | list($element) = $qname; |
||
123 | } |
||
124 | $ns = $xml->lookupNamespaceUri($prefix); |
||
125 | $type = ($ns === null ) ? $element : implode(':', [$ns, $element]); |
||
126 | |||
127 | // now check if we have a handler registered for it |
||
128 | $handler = Utils::getContainer()->getExtensionHandler($type); |
||
129 | if ($handler === null) { |
||
130 | // we don't have a handler, proceed with unknown identifier |
||
131 | $protocols = self::getAttribute($xml, 'protocolSupportEnumeration'); |
||
132 | |||
133 | $validUntil = self::getAttribute($xml, 'validUntil', null); |
||
134 | $orgs = Organization::getChildrenOfClass($xml); |
||
135 | Assert::maxCount($orgs, 1, 'More than one Organization found in this descriptor', TooManyElementsException::class); |
||
136 | |||
137 | $extensions = Extensions::getChildrenOfClass($xml); |
||
138 | Assert::maxCount($extensions, 1, 'Only one md:Extensions element is allowed.', TooManyElementsException::class); |
||
139 | |||
140 | return new UnknownRoleDescriptor( |
||
141 | new Chunk($xml), |
||
142 | $type, |
||
143 | preg_split('/[\s]+/', trim($protocols)), |
||
144 | self::getAttribute($xml, 'ID', null), |
||
145 | $validUntil !== null ? XMLUtils::xsDateTimeToTimestamp($validUntil) : null, |
||
146 | self::getAttribute($xml, 'cacheDuration', null), |
||
147 | !empty($extensions) ? $extensions[0] : null, |
||
148 | self::getAttribute($xml, 'errorURL', null), |
||
149 | KeyDescriptor::getChildrenOfClass($xml), |
||
150 | !empty($orgs) ? $orgs[0] : null, |
||
151 | ContactPerson::getChildrenOfClass($xml), |
||
152 | ); |
||
153 | } |
||
154 | |||
155 | Assert::subclassOf( |
||
156 | $handler, |
||
157 | AbstractRoleDescriptor::class, |
||
158 | 'Elements implementing RoleDescriptor must extend \SimpleSAML\SAML2\XML\saml\AbstractRoleDescriptor.', |
||
159 | ); |
||
160 | |||
161 | return $handler::fromXML($xml); |
||
162 | } |
||
182 |
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.