Conditions | 10 |
Paths | 25 |
Total Lines | 28 |
Code Lines | 16 |
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 |
||
9 | public function fetch($url, $allMeta = null) |
||
10 | { |
||
11 | $html = $this->curl_get_contents($url); |
||
12 | |||
13 | /** |
||
14 | * parsing starts here:. |
||
15 | */ |
||
16 | $doc = new DOMDocument(); |
||
17 | @$doc->loadHTML('<?xml encoding="utf-8" ?>'.$html); |
||
|
|||
18 | |||
19 | $tags = $doc->getElementsByTagName('meta'); |
||
20 | $metadata = []; |
||
21 | foreach ($tags as $tag) { |
||
22 | $metaproperty = ($tag->hasAttribute('property')) ? $tag->getAttribute('property') : $tag->getAttribute('name'); |
||
23 | if (!$allMeta && $metaproperty && strpos($tag->getAttribute('property'), 'og:') === 0) { |
||
24 | $key = strtr(substr($metaproperty, 3), '-', '_'); |
||
25 | $value = $tag->getAttribute('content'); |
||
26 | } |
||
27 | if ($allMeta && $metaproperty) { |
||
28 | $key = (strpos($metaproperty, 'og:') === 0) ? strtr(substr($metaproperty, 3), '-', '_') : $metaproperty; |
||
29 | $value = $tag->getAttribute('content'); |
||
30 | } |
||
31 | if (!empty($key)) { |
||
32 | $metadata[$key] = $value; |
||
33 | } |
||
34 | } |
||
35 | |||
36 | return $metadata; |
||
37 | } |
||
55 |
If you suppress an error, we recommend checking for the error condition explicitly: