Json   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 39
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getComponent() 0 8 1
A __construct() 0 13 3
A setJson() 0 3 1
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
}