Failed Conditions
Pull Request — master (#6)
by Sander
01:53
created

lib/Utility/Evernote.php (2 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Nextcloud - passman
4
 *
5
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
6
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\OwnNote\Utility;
25
26
27
use DateTime;
28
use DOMDocument;
29
use OC\Files\Filesystem;
30
31
class Evernote {
32
33
	/**
34
	 * @param $folder
35
	 * @param $file
36
	 */
37
	public static function checkEvernote($folder, $file) {
38
		$utils = new Utils();
39
		$html = "";
0 ignored issues
show
$html is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
40
		if ($html = Filesystem::file_get_contents($folder . "/" . $file)) {
41
			$DOM = new DOMDocument;
42
			$DOM->loadHTML($html);
43
			$items = $DOM->getElementsByTagName('meta');
44
			$isEvernote = false;
45 View Code Duplication
			for ($i = 0; $i < $items->length; $i++) {
46
				$item = $items->item($i);
47
				if ($item->hasAttributes()) {
48
					$attrs = $item->attributes;
49
					foreach ($attrs as $a => $attr) {
50
						if ($attr->name == "name") {
51
							if ($attr->value == "exporter-version" || $attr->value == "Generator") {
52
								$isEvernote = true;
53
								continue;
54
							}
55
						}
56
					}
57
				}
58
			}
59
			if ($isEvernote) {
60
				$items = $DOM->getElementsByTagName('img');
61
				$isEvernote = false;
0 ignored issues
show
$isEvernote is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
62
				for ($i = 0; $i < $items->length; $i++) {
63
					$item = $items->item($i);
64
					if ($item->hasAttributes()) {
65
						$attrs = $item->attributes;
66
						foreach ($attrs as $a => $attr) {
67
							if ($attr->name == "src") {
68
								$url = $attr->value;
69
								if (!$utils->startsWith($url, "http") && !$utils->startsWith($url, "/") && !$utils->startsWith($url, "data")) {
70 View Code Duplication
									if ($data = Filesystem::file_get_contents($folder . "/" . $url)) {
71
										$type = pathinfo($url, PATHINFO_EXTENSION);
72
										$base64 = "data:image/" . $type . ";base64," . base64_encode($data);
73
										$html = str_replace($url, $base64, $html);
74
									}
75
								}
76
							}
77
						}
78
					}
79
				}
80
				Filesystem::file_put_contents($folder . "/" . $file, $html);
81
			}
82
		}
83
	}
84
}