Passed
Push — master ( a9ba5a...6cd513 )
by Бабичев
02:53
created

JSON::encode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Bavix\Helpers;
4
5
class JSON
6
{
7
8
    /**
9
     * @param mixed $value
10
     * @param int   $options
11
     *
12
     * @return string
13
     */
14 3
    public static function encode($value, $options = JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK)
15
    {
16 3
        if ($value instanceof \Traversable)
17
        {
18 1
            $value = \iterator_to_array($value);
19
        }
20
21 3
        return \json_encode($value, $options);
22
    }
23
24
    /**
25
     * @param string $json
26
     * @param bool   $assoc
27
     * @param int    $options
28
     *
29
     * @return mixed
30
     */
31 1
    public static function decode($json, $assoc = true, $options = 0)
32
    {
33 1
        return \json_decode($json, $assoc, 512, $options);
34
    }
35
36
}
37