Conditions | 21 |
Paths | 28 |
Total Lines | 100 |
Code Lines | 79 |
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 |
||
114 | public static function fromXML(DOMElement $xml): static |
||
115 | { |
||
116 | Assert::same($xml->localName, 'EntityDescriptor', InvalidDOMElementException::class); |
||
117 | Assert::same($xml->namespaceURI, EntityDescriptor::NS, InvalidDOMElementException::class); |
||
118 | |||
119 | $validUntil = self::getOptionalAttribute($xml, 'validUntil', null); |
||
120 | SAMLAssert::nullOrValidDateTime($validUntil); |
||
121 | |||
122 | $extensions = Extensions::getChildrenOfClass($xml); |
||
123 | Assert::maxCount($extensions, 1, 'Only one md:Extensions element is allowed.', TooManyElementsException::class); |
||
124 | |||
125 | $signature = Signature::getChildrenOfClass($xml); |
||
126 | Assert::maxCount($signature, 1, 'Only one ds:Signature element is allowed.', TooManyElementsException::class); |
||
127 | |||
128 | $entityID = self::getAttribute($xml, 'entityID'); |
||
129 | $roleDescriptors = []; |
||
130 | $affiliationDescriptor = null; |
||
131 | $organization = null; |
||
132 | $contactPersons = []; |
||
133 | $additionalMetadataLocation = []; |
||
134 | foreach ($xml->childNodes as $node) { |
||
135 | if ( |
||
136 | !($node instanceof DOMElement) |
||
137 | || ($node->namespaceURI !== C::NS_MD) |
||
138 | ) { |
||
139 | continue; |
||
140 | } |
||
141 | |||
142 | switch ($node->localName) { |
||
143 | case 'Extensions': |
||
144 | continue 2; |
||
145 | case 'IDPSSODescriptor': |
||
146 | $roleDescriptors[] = IDPSSODescriptor::fromXML($node); |
||
147 | break; |
||
148 | case 'SPSSODescriptor': |
||
149 | $roleDescriptors[] = SPSSODescriptor::fromXML($node); |
||
150 | break; |
||
151 | case 'AuthnAuthorityDescriptor': |
||
152 | $roleDescriptors[] = AuthnAuthorityDescriptor::fromXML($node); |
||
153 | break; |
||
154 | case 'AttributeAuthorityDescriptor': |
||
155 | $roleDescriptors[] = AttributeAuthorityDescriptor::fromXML($node); |
||
156 | break; |
||
157 | case 'PDPDescriptor': |
||
158 | $roleDescriptors[] = PDPDescriptor::fromXML($node); |
||
159 | break; |
||
160 | case 'AffiliationDescriptor': |
||
161 | if ($affiliationDescriptor !== null) { |
||
162 | throw new TooManyElementsException('More than one AffiliationDescriptor in the entity.'); |
||
163 | } |
||
164 | $affiliationDescriptor = AffiliationDescriptor::fromXML($node); |
||
165 | break; |
||
166 | case 'Organization': |
||
167 | if ($organization !== null) { |
||
168 | throw new TooManyElementsException('More than one Organization in the entity.'); |
||
169 | } |
||
170 | $organization = Organization::fromXML($node); |
||
171 | break; |
||
172 | case 'ContactPerson': |
||
173 | $contactPersons[] = ContactPerson::fromXML($node); |
||
174 | break; |
||
175 | case 'AdditionalMetadataLocation': |
||
176 | $additionalMetadataLocation[] = AdditionalMetadataLocation::fromXML($node); |
||
177 | break; |
||
178 | default: |
||
179 | $roleDescriptors[] = UnknownRoleDescriptor::fromXML($node); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | Assert::false( |
||
184 | empty($roleDescriptors) && is_null($affiliationDescriptor), |
||
185 | 'Must have either one of the RoleDescriptors or an AffiliationDescriptor in EntityDescriptor.', |
||
186 | ProtocolViolationException::class, |
||
187 | ); |
||
188 | Assert::false( |
||
189 | !empty($roleDescriptors) && !is_null($affiliationDescriptor), |
||
190 | 'AffiliationDescriptor cannot be combined with other RoleDescriptor elements in EntityDescriptor.', |
||
191 | ProtocolViolationException::class, |
||
192 | ); |
||
193 | |||
194 | $entity = new static( |
||
195 | $entityID, |
||
196 | self::getOptionalAttribute($xml, 'ID', null), |
||
197 | $validUntil !== null ? new DateTimeImmutable($validUntil) : null, |
||
198 | self::getOptionalAttribute($xml, 'cacheDuration', null), |
||
199 | !empty($extensions) ? $extensions[0] : null, |
||
200 | $roleDescriptors, |
||
201 | $affiliationDescriptor, |
||
202 | $organization, |
||
203 | $contactPersons, |
||
204 | $additionalMetadataLocation, |
||
205 | self::getAttributesNSFromXML($xml), |
||
206 | ); |
||
207 | |||
208 | if (!empty($signature)) { |
||
209 | $entity->setSignature($signature[0]); |
||
210 | $entity->setXML($xml); |
||
211 | } |
||
212 | |||
213 | return $entity; |
||
214 | } |
||
317 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths