| Conditions | 10 |
| Paths | 26 |
| Total Lines | 87 |
| Code Lines | 57 |
| 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 |
||
| 119 | private function downloadMetadata() |
||
| 120 | { |
||
| 121 | Logger::debug($this->logLoc . 'Downloading metadata from ' . var_export($this->url, true)); |
||
| 122 | $configUtils = new Utils\Config(); |
||
| 123 | |||
| 124 | $context = ['ssl' => []]; |
||
| 125 | if ($this->sslCAFile !== null) { |
||
| 126 | $context['ssl']['cafile'] = $configUtils->getCertPath($this->sslCAFile); |
||
| 127 | Logger::debug( |
||
| 128 | $this->logLoc . 'Validating https connection against CA certificate(s) found in ' . |
||
| 129 | var_export($context['ssl']['cafile'], true) |
||
| 130 | ); |
||
| 131 | $context['ssl']['verify_peer'] = true; |
||
| 132 | $context['ssl']['CN_match'] = parse_url($this->url, PHP_URL_HOST); |
||
| 133 | } |
||
| 134 | |||
| 135 | try { |
||
| 136 | $httpUtils = new Utils\HTTP(); |
||
| 137 | $data = $httpUtils->fetch($this->url, $context, false); |
||
| 138 | } catch (Error\Exception $e) { |
||
| 139 | Logger::error($this->logLoc . 'Unable to load metadata from ' . var_export($this->url, true)); |
||
| 140 | return null; |
||
| 141 | } |
||
| 142 | |||
| 143 | $doc = new DOMDocument(); |
||
| 144 | /** @var string $data */ |
||
| 145 | $res = $doc->loadXML($data); |
||
| 146 | if (!$res) { |
||
| 147 | Logger::error($this->logLoc . 'Error parsing XML from ' . var_export($this->url, true)); |
||
| 148 | return null; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** @psalm-var \DOMElement[] $root */ |
||
| 152 | $root = XPath::xpQuery( |
||
| 153 | $doc->documentElement, |
||
| 154 | '/saml_metadata:EntityDescriptor|/saml_metadata:EntitiesDescriptor', |
||
| 155 | XPath::getXPath($doc->documentElement), |
||
| 156 | ); |
||
| 157 | |||
| 158 | if (count($root) === 0) { |
||
| 159 | Logger::error( |
||
| 160 | $this->logLoc . 'No <EntityDescriptor> or <EntitiesDescriptor> in metadata from ' . |
||
| 161 | var_export($this->url, true) |
||
| 162 | ); |
||
| 163 | return null; |
||
| 164 | } |
||
| 165 | |||
| 166 | if (count($root) > 1) { |
||
| 167 | Logger::error( |
||
| 168 | $this->logLoc . 'More than one <EntityDescriptor> or <EntitiesDescriptor> in metadata from ' . |
||
| 169 | var_export($this->url, true) |
||
| 170 | ); |
||
| 171 | return null; |
||
| 172 | } |
||
| 173 | |||
| 174 | $root = $root[0]; |
||
| 175 | try { |
||
| 176 | if ($root->localName === 'EntityDescriptor') { |
||
| 177 | $md = EntityDescriptor::fromXML($root); |
||
| 178 | } else { |
||
| 179 | $md = EntitiesDescriptor::fromXML($root); |
||
| 180 | } |
||
| 181 | } catch (Exception $e) { |
||
| 182 | Logger::error( |
||
| 183 | $this->logLoc . 'Unable to parse metadata from ' . |
||
| 184 | var_export($this->url, true) . ': ' . $e->getMessage() |
||
| 185 | ); |
||
| 186 | return null; |
||
| 187 | } |
||
| 188 | |||
| 189 | if ($this->certificate !== null) { |
||
| 190 | $file = $configUtils->getCertPath($this->certificate); |
||
| 191 | $certData = file_get_contents($file); |
||
| 192 | if ($certData === false) { |
||
| 193 | throw new Exception('Error loading certificate from ' . var_export($file, true)); |
||
| 194 | } |
||
| 195 | |||
| 196 | $verifier = (new SignatureAlgorithmFactory())->getAlgorithm( |
||
| 197 | $md->getSignature()->getSignedInfo()->getSignatureMethod()->getAlgorithm(), |
||
| 198 | PublicKey::fromFile($file), |
||
| 199 | ); |
||
| 200 | |||
| 201 | $md = $md->verify($verifier); |
||
| 202 | Logger::debug($this->logLoc . 'Validated signature on metadata from ' . var_export($this->url, true)); |
||
| 203 | } |
||
| 204 | |||
| 205 | return $md; |
||
| 206 | } |
||
| 277 |
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