Issues (37)

app/Console/VerifyJSON.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * VerifyJSON.php
6
 * Copyright (c) 2020 [email protected].
7
 *
8
 * This file is part of the Firefly III bunq importer
9
 * (https://github.com/firefly-iii/bunq-importer).
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
23
 */
24
25
namespace App\Console;
26
27
use Exception;
28
use JsonException;
29
30
/**
31
 * Trait VerifyJSON.
32
 */
33
trait VerifyJSON
34
{
35
    /**
36
     * @param string $file
37
     *
38
     * @return bool
39
     */
40
    private function verifyJSON(string $file): bool
41
    {
42
        // basic check on the JSON.
43
        $json = file_get_contents($file);
44
        try {
45
            $configuration = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
0 ignored issues
show
The assignment to $configuration is dead and can be removed.
Loading history...
46
        } catch (Exception | JsonException $e) {
47
            $message = sprintf('The importer can\'t import: could not decode the JSON in the config file: %s', $e->getMessage());
48
            app('log')->error($message);
49
50
            return false;
51
        }
52
53
        return true;
54
    }
55
}
56