brantje /
nextnote
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 DOMDocument; |
||
| 28 | use OC\Files\Filesystem; |
||
| 29 | |||
| 30 | class Evernote { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param $folder |
||
| 34 | * @param string $file |
||
| 35 | */ |
||
| 36 | public static function checkEvernote($folder, $file) { |
||
| 37 | $utils = new Utils(); |
||
| 38 | $html = ""; |
||
|
0 ignored issues
–
show
|
|||
| 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; |
||
|
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 Loading history...
|
|||
| 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
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.