Passed
Push — master ( 7b08a2...d0c126 )
by Supun
03:14
created

Json::toObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Lifeeka\JSQL\Helpers;
4
5
/**
6
 * Class MysqlExtractor.
7
 */
8
class Json
9
{
10
    public $json_text;
11
    public $json_array;
12
    public $main_table_name = "main";
13
14
    /**
15
     * Json constructor.
16
     *
17
     * @param string $json
18
     */
19
    public function __construct(String $json)
20
    {
21
        $this->json_text = $json;
22
    }
23
24
    /**
25
     * @return mixed
26
     */
27
    public function toArray()
28
    {
29
        return json_decode($this->json_text, true);
30
    }
31
32
    /**
33
     * @return mixed
34
     */
35
    public function toObject()
36
    {
37
        $json_object = $this->validate(json_decode($this->json_text));
38
        return $json_object;
39
    }
40
41
42
    /**
43
     * @param $json
44
     * @return object
45
     */
46
    public function validate($json)
47
    {
48
        if (is_array($json)) {
49
            return (object)[
50
                $this->main_table_name=>$json
51
            ];
52
        }
53
        return $json;
54
    }
55
}
56