Kind::map()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Mapper;
6
7
/**
8
 * Class Kind
9
 * @package Mapper
10
 */
11
abstract class Kind implements KindInterface {
12
13
    /**
14
     * @var mixed
15
     */
16
    protected $data;
17
18
    /**
19
     * @var object
20
     */
21
    private $object;
22
23
    /**
24
     * @var Kernel
25
     */
26
    private $kernel;
27
28
    /**
29
     * @return array
30
     */
31
    abstract protected function prepareDataKernel(): array;
32
33
    /**
34
     * Kind constructor.
35
     * @param object $object
36
     */
37 4
    public function __construct($object) {
38 4
        $this->setupKernel($object)
39 4
            ->setObject($object);
40 4
    }
41
42
    /**
43
     * @return object
44
     */
45 2
    public function getObject() {
46 2
        return $this->object;
47
    }
48
49
    /**
50
     * @param object $object
51
     * @return Kind
52
     * @throws \Exception
53
     */
54 4
    public function setObject($object): Kind {
55 4
        if (is_object($object)) {
56 4
            $this->object = $object;
57
58 4
            $this->getKernel()
59 4
                ->setObject($object);
60
        } else {
61 1
            throw new \Exception('Invalid object passed');
62
        }
63
64 4
        return $this;
65
    }
66
67
    /**
68
     * @return Kernel
69
     */
70 4
    protected function getKernel(): Kernel {
71 4
        return $this->kernel;
72
    }
73
74
    /**
75
     * @param Kernel $kernel
76
     * @return Kind
77
     */
78 4
    private function setKernel(Kernel $kernel): Kind {
79 4
        $this->kernel = $kernel;
80
81 4
        return $this;
82
    }
83
84
    /**
85
     * @param object $object
86
     * @return Kind
87
     */
88 4
    private function setupKernel($object): Kind {
89 4
        return $this->setKernel(
90 4
            new Kernel(
91 4
                $this->prepareDataKernel(),
92
                $object
93
            )
94
        );
95
    }
96
97
    /**
98
     * @return object
99
     */
100 2
    public function map() {
101 2
        return $this->getKernel()
102 2
            ->map();
103
    }
104
105
}