Json::setDepth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Swaggest\Json;
4
5
class Json
6
{
7
    private $value;
8
    private $options = 0;
9
    private $depth = 512;
10
11
    /**
12
     * Json constructor.
13
     * @param $value
14
     */
15
    public function __construct($value)
16
    {
17
        $this->value = $value;
18
    }
19
20
    public function addOption($option)
21
    {
22
        $this->options += $option;
23
        return $this;
24
    }
25
26
    public function setDepth($depth) {
27
        $this->depth = $depth;
28
        return $this;
29
    }
30
31
    public function __toString()
32
    {
33
        if ($this->depth !== 512 && PHP_VERSION_ID > 50500) {
34
            $result = json_encode($this->value, $this->options, $this->depth);
35
        } else {
36
            $result = json_encode($this->value, $this->options);
37
        }
38
        $result = str_replace(array('"' . RawJson::MARKER, RawJson::MARKER . '"'), '', $result);
39
        return $result;
40
    }
41
}
42