| Conditions | 21 |
| Paths | 28 |
| Total Lines | 98 |
| Code Lines | 78 |
| 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, 'EntityDescriptor', InvalidDOMElementException::class); |
||
| 106 | Assert::same($xml->namespaceURI, EntityDescriptor::NS, InvalidDOMElementException::class); |
||
| 107 | |||
| 108 | $validUntil = self::getAttribute($xml, 'validUntil', null); |
||
| 109 | $extensions = Extensions::getChildrenOfClass($xml); |
||
| 110 | Assert::maxCount($extensions, 1, 'Only one md:Extensions element is allowed.', TooManyElementsException::class); |
||
| 111 | |||
| 112 | $signature = Signature::getChildrenOfClass($xml); |
||
| 113 | Assert::maxCount($signature, 1, 'Only one ds:Signature element is allowed.', TooManyElementsException::class); |
||
| 114 | |||
| 115 | $entityID = self::getAttribute($xml, 'entityID'); |
||
| 116 | $roleDescriptors = []; |
||
| 117 | $affiliationDescriptor = null; |
||
| 118 | $organization = null; |
||
| 119 | $contactPersons = []; |
||
| 120 | $additionalMetadataLocation = []; |
||
| 121 | foreach ($xml->childNodes as $node) { |
||
| 122 | if ( |
||
| 123 | !($node instanceof DOMElement) |
||
| 124 | || ($node->namespaceURI !== C::NS_MD) |
||
| 125 | ) { |
||
| 126 | continue; |
||
| 127 | } |
||
| 128 | |||
| 129 | switch ($node->localName) { |
||
| 130 | case 'Extensions': |
||
| 131 | continue 2; |
||
| 132 | case 'IDPSSODescriptor': |
||
| 133 | $roleDescriptors[] = IDPSSODescriptor::fromXML($node); |
||
| 134 | break; |
||
| 135 | case 'SPSSODescriptor': |
||
| 136 | $roleDescriptors[] = SPSSODescriptor::fromXML($node); |
||
| 137 | break; |
||
| 138 | case 'AuthnAuthorityDescriptor': |
||
| 139 | $roleDescriptors[] = AuthnAuthorityDescriptor::fromXML($node); |
||
| 140 | break; |
||
| 141 | case 'AttributeAuthorityDescriptor': |
||
| 142 | $roleDescriptors[] = AttributeAuthorityDescriptor::fromXML($node); |
||
| 143 | break; |
||
| 144 | case 'PDPDescriptor': |
||
| 145 | $roleDescriptors[] = PDPDescriptor::fromXML($node); |
||
| 146 | break; |
||
| 147 | case 'AffiliationDescriptor': |
||
| 148 | if ($affiliationDescriptor !== null) { |
||
| 149 | throw new TooManyElementsException('More than one AffiliationDescriptor in the entity.'); |
||
| 150 | } |
||
| 151 | $affiliationDescriptor = AffiliationDescriptor::fromXML($node); |
||
| 152 | break; |
||
| 153 | case 'Organization': |
||
| 154 | if ($organization !== null) { |
||
| 155 | throw new TooManyElementsException('More than one Organization in the entity.'); |
||
| 156 | } |
||
| 157 | $organization = Organization::fromXML($node); |
||
| 158 | break; |
||
| 159 | case 'ContactPerson': |
||
| 160 | $contactPersons[] = ContactPerson::fromXML($node); |
||
| 161 | break; |
||
| 162 | case 'AdditionalMetadataLocation': |
||
| 163 | $additionalMetadataLocation[] = AdditionalMetadataLocation::fromXML($node); |
||
| 164 | break; |
||
| 165 | default: |
||
| 166 | $roleDescriptors[] = UnknownRoleDescriptor::fromXML($node); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | Assert::false( |
||
| 171 | empty($roleDescriptors) && is_null($affiliationDescriptor), |
||
| 172 | 'Must have either one of the RoleDescriptors or an AffiliationDescriptor in EntityDescriptor.', |
||
| 173 | ProtocolViolationException::class, |
||
| 174 | ); |
||
| 175 | Assert::false( |
||
| 176 | !empty($roleDescriptors) && !is_null($affiliationDescriptor), |
||
| 177 | 'AffiliationDescriptor cannot be combined with other RoleDescriptor elements in EntityDescriptor.', |
||
| 178 | ProtocolViolationException::class, |
||
| 179 | ); |
||
| 180 | |||
| 181 | $entity = new static( |
||
| 182 | $entityID, |
||
| 183 | self::getAttribute($xml, 'ID', null), |
||
| 184 | $validUntil !== null ? XMLUtils::xsDateTimeToTimestamp($validUntil) : null, |
||
| 185 | self::getAttribute($xml, 'cacheDuration', null), |
||
| 186 | !empty($extensions) ? $extensions[0] : null, |
||
| 187 | $roleDescriptors, |
||
| 188 | $affiliationDescriptor, |
||
| 189 | $organization, |
||
| 190 | $contactPersons, |
||
| 191 | $additionalMetadataLocation, |
||
| 192 | self::getAttributesNSFromXML($xml), |
||
| 193 | ); |
||
| 194 | |||
| 195 | if (!empty($signature)) { |
||
| 196 | $entity->setSignature($signature[0]); |
||
| 197 | $entity->setXML($xml); |
||
| 198 | } |
||
| 199 | |||
| 200 | return $entity; |
||
| 201 | } |
||
| 304 |
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