| Conditions | 14 |
| Paths | 146 |
| Total Lines | 45 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 15 | ||
| Bugs | 2 | 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 |
||
| 10 | public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOWARNING | LIBXML_NOERROR, $userAgent = 'Curl') |
||
| 11 | { |
||
| 12 | $html = $this->curl_get_contents($url, $lang, $userAgent); |
||
| 13 | /** |
||
| 14 | * parsing starts here:. |
||
| 15 | */ |
||
| 16 | $doc = new DOMDocument(); |
||
| 17 | |||
| 18 | $libxml_previous_state = libxml_use_internal_errors(true); |
||
| 19 | $doc->loadHTML('<?xml encoding="utf-8" ?>'.$html, $options); |
||
| 20 | //catch possible errors due to empty or malformed HTML |
||
| 21 | if ($options > 0 && ($options & (LIBXML_NOWARNING | LIBXML_NOERROR)) == 0) { |
||
| 22 | Log::warning(libxml_get_errors()); |
||
|
|
|||
| 23 | } |
||
| 24 | libxml_clear_errors(); |
||
| 25 | // restore previous state |
||
| 26 | libxml_use_internal_errors($libxml_previous_state); |
||
| 27 | |||
| 28 | $tags = $doc->getElementsByTagName('meta'); |
||
| 29 | $metadata = []; |
||
| 30 | foreach ($tags as $tag) { |
||
| 31 | $metaproperty = ($tag->hasAttribute('property')) ? $tag->getAttribute('property') : $tag->getAttribute('name'); |
||
| 32 | if (!$allMeta && $metaproperty && strpos($tag->getAttribute('property'), 'og:') === 0) { |
||
| 33 | $key = strtr(substr($metaproperty, 3), '-', '_'); |
||
| 34 | $value = $this->get_meta_value($tag); |
||
| 35 | } |
||
| 36 | if ($allMeta && $metaproperty) { |
||
| 37 | $key = (strpos($metaproperty, 'og:') === 0) ? strtr(substr($metaproperty, 3), '-', '_') : $metaproperty; |
||
| 38 | $value = $this->get_meta_value($tag); |
||
| 39 | } |
||
| 40 | if (!empty($key)) { |
||
| 41 | $metadata[$key] = $value; |
||
| 42 | } |
||
| 43 | /* |
||
| 44 | * Verify image url |
||
| 45 | */ |
||
| 46 | if (isset($metadata['image'])) { |
||
| 47 | $isValidImageUrl = $this->verify_image_url($metadata['image']); |
||
| 48 | if (!$isValidImageUrl) { |
||
| 49 | $metadata['image'] = ''; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | return $metadata; |
||
| 55 | } |
||
| 126 |
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