Completed
Pull Request — master (#12)
by
unknown
04:08 queued 02:45
created

JsonDecoder::decode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 4
cts 5
cp 0.8
crap 2.032
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace League\JsonReference\Decoder;
4
5
use League\JsonReference\DecoderInterface;
6
use League\JsonReference\DecodingException;
7
8
final class JsonDecoder implements DecoderInterface
9
{
10
    /**
11
     * @var bool
12
     */
13
    private $assoc;
14
15
    /**
16
     * @var int
17
     */
18
    private $depth;
19
20
    /**
21
     * @var int
22
     */
23
    private $options;
24
25
    /**
26
     * @param bool $assoc
27
     * @param int  $depth
28
     * @param int  $options
29
     */
30 106
    public function __construct($assoc = false, $depth = 512, $options = JSON_BIGINT_AS_STRING)
31
    {
32 106
        $this->assoc   = $assoc;
33 106
        $this->depth   = $depth;
34 106
        $this->options = $options;
35 106
    }
36
37
    
38
    /**
39
     * {@inheritdoc}
40
     */
41 54
    public function decode($schema)
42
    {
43 54
        $data = json_decode($schema, $this->assoc, $this->depth, $this->options);
44
45 54
        if (json_last_error() !== JSON_ERROR_NONE) {
46
            throw new DecodingException(sprintf('Invalid JSON: %s', json_last_error_msg()));
47
        }
48
49 54
        return $data;
50
    }
51
}
52