Conditions | 17 |
Paths | 13 |
Total Lines | 47 |
Code Lines | 33 |
Lines | 19 |
Ratio | 40.43 % |
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 |
||
36 | public static function checkEvernote($folder, $file) { |
||
37 | $utils = new Utils(); |
||
38 | $html = ""; |
||
|
|||
39 | if ($html = Filesystem::file_get_contents($folder . "/" . $file)) { |
||
40 | $DOM = new DOMDocument; |
||
41 | $DOM->loadHTML($html); |
||
42 | $items = $DOM->getElementsByTagName('meta'); |
||
43 | $isEvernote = false; |
||
44 | View Code Duplication | for ($i = 0; $i < $items->length; $i++) { |
|
45 | $item = $items->item($i); |
||
46 | if ($item->hasAttributes()) { |
||
47 | $attrs = $item->attributes; |
||
48 | foreach ($attrs as $a => $attr) { |
||
49 | if ($attr->name == "name") { |
||
50 | if ($attr->value == "exporter-version" || $attr->value == "Generator") { |
||
51 | $isEvernote = true; |
||
52 | continue; |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | if ($isEvernote) { |
||
59 | $items = $DOM->getElementsByTagName('img'); |
||
60 | $isEvernote = false; |
||
61 | for ($i = 0; $i < $items->length; $i++) { |
||
62 | $item = $items->item($i); |
||
63 | if ($item->hasAttributes()) { |
||
64 | $attrs = $item->attributes; |
||
65 | foreach ($attrs as $a => $attr) { |
||
66 | if ($attr->name == "src") { |
||
67 | $url = $attr->value; |
||
68 | if (!$utils->startsWith($url, "http") && !$utils->startsWith($url, "/") && !$utils->startsWith($url, "data")) { |
||
69 | View Code Duplication | if ($data = Filesystem::file_get_contents($folder . "/" . $url)) { |
|
70 | $type = pathinfo($url, PATHINFO_EXTENSION); |
||
71 | $base64 = "data:image/" . $type . ";base64," . base64_encode($data); |
||
72 | $html = str_replace($url, $base64, $html); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | Filesystem::file_put_contents($folder . "/" . $file, $html); |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.