| Conditions | 17 |
| Paths | 13 |
| Total Lines | 45 |
| Code Lines | 31 |
| 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 |
||
| 36 | public static function checkEvernote($folder, $file) { |
||
| 37 | $utils = new Utils(); |
||
| 38 | if ($html = Filesystem::file_get_contents($folder . "/" . $file)) { |
||
| 39 | $DOM = new DOMDocument; |
||
| 40 | $DOM->loadHTML($html); |
||
| 41 | $items = $DOM->getElementsByTagName('meta'); |
||
| 42 | $isEvernote = false; |
||
| 43 | for ($i = 0; $i < $items->length; $i++) { |
||
| 44 | $item = $items->item($i); |
||
| 45 | if ($item->hasAttributes()) { |
||
| 46 | $attrs = $item->attributes; |
||
| 47 | foreach ($attrs as $a => $attr) { |
||
| 48 | if ($attr->name == "name") { |
||
| 49 | if ($attr->value == "exporter-version" || $attr->value == "Generator") { |
||
| 50 | $isEvernote = true; |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | if ($isEvernote) { |
||
| 58 | $items = $DOM->getElementsByTagName('img'); |
||
| 59 | for ($i = 0; $i < $items->length; $i++) { |
||
| 60 | $item = $items->item($i); |
||
| 61 | if ($item->hasAttributes()) { |
||
| 62 | $attrs = $item->attributes; |
||
| 63 | foreach ($attrs as $a => $attr) { |
||
| 64 | if ($attr->name == "src") { |
||
| 65 | $url = $attr->value; |
||
| 66 | if (!$utils->startsWith($url, "http") && !$utils->startsWith($url, "/") && !$utils->startsWith($url, "data")) { |
||
| 67 | if ($data = Filesystem::file_get_contents($folder . "/" . $url)) { |
||
| 68 | $type = pathinfo($url, PATHINFO_EXTENSION); |
||
| 69 | $base64 = "data:image/" . $type . ";base64," . base64_encode($data); |
||
| 70 | $html = str_replace($url, $base64, $html); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | Filesystem::file_put_contents($folder . "/" . $file, $html); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |