ColumnMap::getType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace MetadataMapping\Metadata;
6
7
use ReflectionProperty;
8
use ReflectionException;
9
use Exception\ApplicationException;
10
use BasePatterns\LayerSupertype\DomainObject;
11
12
class ColumnMap
13
{
14
    private string $columnName;
15
16
    private string $fieldName;
17
18
    private string $type;
19
20
    private DataMap $dataMap;
21
22
    private ReflectionProperty $field;
23
24 5
    public function __construct(
25
        string $columnName,
26
        string $fieldName,
27
        string $type,
28
        DataMap $dataMap
29
    ) {
30 5
        $this->columnName = $columnName;
31 5
        $this->fieldName = $fieldName;
32 5
        $this->type = $type;
33 5
        $this->dataMap = $dataMap;
34 5
        $this->initField();
35 5
    }
36
37 5
    public function getColumnName(): string
38
    {
39 5
        return $this->columnName;
40
    }
41
42 2
    public function getFieldName(): string
43
    {
44 2
        return $this->fieldName;
45
    }
46
47 4
    public function getType(): string
48
    {
49
        return $this->type;
50 4
    }
51
52
    public function setField(DomainObject $object, $value): void
53
    {
54
        try {
55
            $this->field->setValue($object, $value);
56
        } catch (ReflectionException $e) {
57
            throw new ApplicationException(
58 4
                sprintf("Error in setting %s", $this->fieldName),
59
                -1,
60 5
                $e
61
            );
62
        }
63 5
    }
64 5
65 5
    private function initField(): void
66
    {
67 5
        try {
68
            $this->field = new ReflectionProperty(
69
                $this->dataMap->getDomainClass()->getName(),
70
                $this->fieldName
71
            );
72
            $this->field->setAccessible(true);
73
        } catch (ReflectionException $e) {
74
            throw new ApplicationException(
75 5
                sprintf("Unable to set up field: %s", $this->fieldName),
76
                -1,
77
                $e
78
            );
79
        }
80
    }
81
}
82