Json   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 48
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getData() 0 3 1
A setData() 0 8 1
A prepareDataKernel() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Mapper\Kind;
6
7
use Mapper\Kind;
8
9
/**
10
 * Class Json
11
 * @package Mapper\Kind
12
 */
13
class Json extends Kind {
14
15
    /**
16
     * Json constructor.
17
     * @param string $data
18
     * @param object $object
19
     */
20 3
    public function __construct(string $data, $object) {
21 3
        $this->data = $data;
22
23 3
        parent::__construct($object);
24 3
    }
25
26
    /**
27
     * @return string
28
     */
29 3
    public function getData(): string {
30 3
        return $this->data;
31
    }
32
33
    /**
34
     * @param string $data
35
     * @return Json
36
     */
37 2
    public function setData(string $data): Json {
38 2
        $this->data = $data;
39
40 2
        $this->getKernel()
41 2
            ->setData($this->prepareDataKernel());
42
43 1
        return $this;
44
    }
45
46
    /**
47
     * @return array
48
     * @throws \Exception
49
     */
50 3
    protected function prepareDataKernel(): array {
51 3
        $data = json_decode($this->getData(), true);
52
53 3
        if (is_null($data)) {
54 1
            throw new \Exception('Invalid json passed');
55
        }
56
57 3
        return $data;
58
    }
59
60
}