| Conditions | 25 |
| Paths | 1842 |
| Total Lines | 84 |
| Code Lines | 56 |
| Lines | 5 |
| Ratio | 5.95 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 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 |
||
| 97 | public function __construct(\DOMElement $xml = null) |
||
| 98 | { |
||
| 99 | parent::__construct($xml); |
||
| 100 | |||
| 101 | if ($xml === null) { |
||
| 102 | return; |
||
| 103 | } |
||
| 104 | |||
| 105 | if (!$xml->hasAttribute('entityID')) { |
||
| 106 | throw new \Exception('Missing required attribute entityID on EntityDescriptor.'); |
||
| 107 | } |
||
| 108 | $this->entityID = $xml->getAttribute('entityID'); |
||
| 109 | |||
| 110 | if ($xml->hasAttribute('ID')) { |
||
| 111 | $this->ID = $xml->getAttribute('ID'); |
||
| 112 | } |
||
| 113 | if ($xml->hasAttribute('validUntil')) { |
||
| 114 | $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil')); |
||
| 115 | } |
||
| 116 | if ($xml->hasAttribute('cacheDuration')) { |
||
| 117 | $this->cacheDuration = $xml->getAttribute('cacheDuration'); |
||
| 118 | } |
||
| 119 | |||
| 120 | $this->Extensions = Extensions::getList($xml); |
||
| 121 | |||
| 122 | for ($node = $xml->firstChild; $node !== null; $node = $node->nextSibling) { |
||
| 123 | if (!($node instanceof \DOMElement)) { |
||
| 124 | continue; |
||
| 125 | } |
||
| 126 | |||
| 127 | if ($node->namespaceURI !== Constants::NS_MD) { |
||
| 128 | continue; |
||
| 129 | } |
||
| 130 | |||
| 131 | switch ($node->localName) { |
||
| 132 | case 'RoleDescriptor': |
||
| 133 | $this->RoleDescriptor[] = new UnknownRoleDescriptor($node); |
||
| 134 | break; |
||
| 135 | case 'IDPSSODescriptor': |
||
| 136 | $this->RoleDescriptor[] = new IDPSSODescriptor($node); |
||
| 137 | break; |
||
| 138 | case 'SPSSODescriptor': |
||
| 139 | $this->RoleDescriptor[] = new SPSSODescriptor($node); |
||
| 140 | break; |
||
| 141 | case 'AuthnAuthorityDescriptor': |
||
| 142 | $this->RoleDescriptor[] = new AuthnAuthorityDescriptor($node); |
||
| 143 | break; |
||
| 144 | case 'AttributeAuthorityDescriptor': |
||
| 145 | $this->RoleDescriptor[] = new AttributeAuthorityDescriptor($node); |
||
| 146 | break; |
||
| 147 | case 'PDPDescriptor': |
||
| 148 | $this->RoleDescriptor[] = new PDPDescriptor($node); |
||
| 149 | break; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | $affiliationDescriptor = Utils::xpQuery($xml, './saml_metadata:AffiliationDescriptor'); |
||
| 154 | if (count($affiliationDescriptor) > 1) { |
||
| 155 | throw new \Exception('More than one AffiliationDescriptor in the entity.'); |
||
| 156 | } elseif (!empty($affiliationDescriptor)) { |
||
| 157 | $this->AffiliationDescriptor = new AffiliationDescriptor($affiliationDescriptor[0]); |
||
| 158 | } |
||
| 159 | |||
| 160 | if (empty($this->RoleDescriptor) && is_null($this->AffiliationDescriptor)) { |
||
| 161 | throw new \Exception('Must have either one of the RoleDescriptors or an AffiliationDescriptor in EntityDescriptor.'); |
||
| 162 | } elseif (!empty($this->RoleDescriptor) && !is_null($this->AffiliationDescriptor)) { |
||
| 163 | throw new \Exception('AffiliationDescriptor cannot be combined with other RoleDescriptor elements in EntityDescriptor.'); |
||
| 164 | } |
||
| 165 | |||
| 166 | $organization = Utils::xpQuery($xml, './saml_metadata:Organization'); |
||
| 167 | View Code Duplication | if (count($organization) > 1) { |
|
|
|
|||
| 168 | throw new \Exception('More than one Organization in the entity.'); |
||
| 169 | } elseif (!empty($organization)) { |
||
| 170 | $this->Organization = new Organization($organization[0]); |
||
| 171 | } |
||
| 172 | |||
| 173 | foreach (Utils::xpQuery($xml, './saml_metadata:ContactPerson') as $cp) { |
||
| 174 | $this->ContactPerson[] = new ContactPerson($cp); |
||
| 175 | } |
||
| 176 | |||
| 177 | foreach (Utils::xpQuery($xml, './saml_metadata:AdditionalMetadataLocation') as $aml) { |
||
| 178 | $this->AdditionalMetadataLocation[] = new AdditionalMetadataLocation($aml); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 252 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.