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