| Conditions | 12 |
| Paths | 28 |
| Total Lines | 71 |
| Code Lines | 48 |
| 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 |
||
| 115 | private function downloadMetadata() |
||
| 116 | { |
||
| 117 | Logger::debug($this->logLoc.'Downloading metadata from '.var_export($this->url, true)); |
||
| 118 | |||
| 119 | $context = ['ssl' => []]; |
||
| 120 | if ($this->sslCAFile !== null) { |
||
| 121 | $context['ssl']['cafile'] = Config::getCertPath($this->sslCAFile); |
||
| 122 | SimpleSAML\Logger::debug($this->logLoc.'Validating https connection against CA certificate(s) found in '. |
||
| 123 | var_export($context['ssl']['cafile'], true)); |
||
| 124 | $context['ssl']['verify_peer'] = true; |
||
| 125 | $context['ssl']['CN_match'] = parse_url($this->url, PHP_URL_HOST); |
||
| 126 | } |
||
| 127 | |||
| 128 | $data = HTTP::fetch($this->url, $context); |
||
| 129 | if ($data === false || $data === null) { |
||
| 130 | Logger::error($this->logLoc.'Unable to load metadata from '.var_export($this->url, true)); |
||
| 131 | return null; |
||
| 132 | } |
||
| 133 | |||
| 134 | $doc = new DOMDocument(); |
||
| 135 | $res = $doc->loadXML($data); |
||
| 136 | if (!$res) { |
||
| 137 | Logger::error($this->logLoc.'Error parsing XML from '.var_export($this->url, true)); |
||
| 138 | return null; |
||
| 139 | } |
||
| 140 | |||
| 141 | $root = Utils::xpQuery($doc->firstChild, '/saml_metadata:EntityDescriptor|/saml_metadata:EntitiesDescriptor'); |
||
| 142 | if (count($root) === 0) { |
||
| 143 | Logger::error($this->logLoc.'No <EntityDescriptor> or <EntitiesDescriptor> in metadata from '. |
||
| 144 | var_export($this->url, true)); |
||
| 145 | return null; |
||
| 146 | } |
||
| 147 | |||
| 148 | if (count($root) > 1) { |
||
| 149 | Logger::error($this->logLoc.'More than one <EntityDescriptor> or <EntitiesDescriptor> in metadata from '. |
||
| 150 | var_export($this->url, true)); |
||
| 151 | return null; |
||
| 152 | } |
||
| 153 | |||
| 154 | $root = $root[0]; |
||
| 155 | try { |
||
| 156 | if ($root->localName === 'EntityDescriptor') { |
||
| 157 | $md = new EntityDescriptor($root); |
||
| 158 | } else { |
||
| 159 | $md = new EntitiesDescriptor($root); |
||
| 160 | } |
||
| 161 | } catch (\Exception $e) { |
||
| 162 | Logger::error($this->logLoc.'Unable to parse metadata from '. |
||
| 163 | var_export($this->url, true).': '.$e->getMessage()); |
||
| 164 | return null; |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($this->certificate !== null) { |
||
| 168 | $file = Config::getCertPath($this->certificate); |
||
| 169 | $certData = file_get_contents($file); |
||
| 170 | if ($certData === false) { |
||
| 171 | throw new Exception('Error loading certificate from '.var_export($file, true)); |
||
| 172 | } |
||
| 173 | |||
| 174 | // Extract the public key from the certificate for validation |
||
| 175 | $key = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, ['type'=>'public']); |
||
| 176 | $key->loadKey($file, true); |
||
| 177 | |||
| 178 | if (!$md->validate($key)) { |
||
| 179 | Logger::error($this->logLoc.'Error validating signature on metadata.'); |
||
| 180 | return null; |
||
| 181 | } |
||
| 182 | Logger::debug($this->logLoc.'Validated signature on metadata from '.var_export($this->url, true)); |
||
| 183 | } |
||
| 184 | |||
| 185 | return $md; |
||
| 186 | } |
||
| 256 |
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