Completed
Push — master ( 7aa7c6...963679 )
by Matt
14s
created

JsonDecoder::__construct()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 6
Code Lines 4

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
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
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 90
    public function __construct($assoc = false, $depth = 512, $options = JSON_BIGINT_AS_STRING)
31
    {
32 90
        $this->assoc   = $assoc;
33 90
        $this->depth   = $depth;
34 90
        $this->options = $options;
35 90
    }
36
37
    
38
    /**
39
     * {@inheritdoc}
40
     */
41 52
    public function decode($schema)
42
    {
43 52
        $data = json_decode($schema, $this->assoc, $this->depth, $this->options);
44
45 52
        if (json_last_error() !== JSON_ERROR_NONE) {
46
            throw new DecodingException(sprintf('Invalid JSON: %s', json_last_error_msg()));
47
        }
48
49 52
        return $data;
50
    }
51
}
52