Json   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseString() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Config\Parse;
6
7
use Enjoys\Config\Parse;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * Class Json
12
 * @package Enjoys\Config\Parse
13
 */
14
class Json extends Parse
15
{
16
17
    /**
18
     * {@inheritDoc}
19
     * @psalm-suppress ArgumentTypeCoercion
20
     */
21 3
    protected function parseString(string $input)
22
    {
23
        /** @var array $result */
24 3
        $result = \json_decode(
25 3
            $input,
26 3
            true,
27 3
            (int)$this->getOption('depth', 512),
28 3
            (int)$this->getOption('options', 0)
29 3
        );
30
31
        //Clear the most recent error
32 3
        \error_clear_last();
33
34 3
        if (\json_last_error() === JSON_ERROR_NONE) {
35 2
            return $result;
36
        }
37 1
        if ($this->logger instanceof LoggerInterface) {
38 1
            $this->logger->error(sprintf('(%s) %s', \json_last_error(), \json_last_error_msg()));
39
        }
40 1
        return null;
41
    }
42
43
}
44