Passed
Push — master ( c423ac...6bd0a6 )
by Enjoys
10:06
created

Json::parseFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Config\Parse;
6
7
use Enjoys\Config\Parse;
8
9
/**
10
 * Class Json
11
 * @package Enjoys\Config\Parse
12
 */
13
class Json extends Parse
14
{
15
16
    /**
17
     * {@inheritDoc}
18
     */
19 3
    protected function parseString(string $input)
20
    {
21
        /** @var array $result */
22 3
        $result = \json_decode(
23 3
            $input,
24 3
            true,
25 3
            (int)$this->getOption('depth', 512),
26 3
            (int)$this->getOption('options', 0)
27 3
        );
28
29
        //Clear the most recent error
30 3
        \error_clear_last();
31
32 3
        if (\json_last_error() === JSON_ERROR_NONE) {
33 2
            return $result;
34
        }
35
36 1
        $this->logger->error(sprintf('(%s) %s', \json_last_error(), \json_last_error_msg()));
37
38 1
        return null;
39
    }
40
41
}
42