Json::setJson()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace FlatPlan\Components;
4
5
class Json extends AbstractComponent {
6
7
    protected $json;
8
    protected $roles = [
9
        'section'
10
    ];
11
12
    /**
13
     * @param string $json
14
     * @return bool
15
     */
16
    public function __construct($json)
17
    {
18
        if (empty($json)) {
19
            return false;
20
        }
21
22
        $object = json_decode($json);
23
        if ($object instanceof \stdClass) {
24
            $this->setJson($object);
25
            $this->setRole('section');
26
        }
27
28
        return false;
29
    }
30
31
    private function setJson($json)
32
    {
33
        $this->json = $json;
34
    }
35
36
    public function getComponent()
37
    {
38
        $component = new \stdClass();
39
        $component->role = $this->getRole();
40
        $component->components = [
41
            $this->json
42
        ];
43
        return $component;
44
    }
45
}