Decoder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5
namespace Json;
6
7
abstract class Decoder
8
{
9
    protected $assoc = false;
10
11
    protected $depth = 512;
12
13
    protected $options = 0;
14
15
    protected $error;
16
17
    public function __construct($depth = 512, $options = 0)
18
    {
19
        $this->depth = $depth;
20
        $this->options = $options;
21
22
        $this->error = new JsonError();
23
    }
24
25
    public function decode($string)
26
    {
27
        $decoded = json_decode(
28
            $string,
29
            $this->assoc,
30
            $this->depth,
31
            $this->options
32
        );
33
34
        if (false === $this->error->hasError()) {
35
            return $decoded;
36
        }
37
38
        $this->error->throwException();
39
    }
40
}
41