DataMap   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 92.59%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 61
ccs 25
cts 27
cp 0.9259
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumnForField() 0 10 3
A addColumn() 0 10 1
A __construct() 0 4 1
A getDomainClass() 0 3 1
A columnList() 0 7 1
A getColumnMaps() 0 3 1
A getTableName() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace MetadataMapping\Metadata;
6
7
use ReflectionClass;
8
use Exception\ApplicationException;
9
10
class DataMap
11
{
12
    private ReflectionClass $domainClass;
13
14
    private string $tableName;
15
16
    private array $columnMaps = [];
17
18 5
    public function __construct(string $domainClass, string $tableName)
19
    {
20 5
        $this->domainClass = new ReflectionClass($domainClass);
21 5
        $this->tableName = $tableName;
22 5
    }
23
24 5
    public function getDomainClass(): ReflectionClass
25
    {
26 5
        return $this->domainClass;
27
    }
28
29 1
    public function getTableName(): string
30
    {
31 1
        return $this->tableName;
32
    }
33
34 5
    public function getColumnMaps(): array
35
    {
36 5
        return $this->columnMaps;
37
    }
38
39 5
    public function addColumn(
40
        string $columnName,
41
        string $type,
42
        string $fieldName
43
    ): void {
44 5
        $this->columnMaps[] = new ColumnMap(
45 5
            $columnName,
46 5
            $fieldName,
47 5
            $type,
48 5
            $this
49
        );
50 5
    }
51
52 1
    public function columnList(): string
53
    {
54
        $columnNames = array_map(function (ColumnMap $columnMap) {
55 1
            return $columnMap->getColumnName();
56 1
        }, $this->columnMaps);
57
58 1
        return " id," . implode(",", $columnNames);
59
    }
60
61 2
    public function getColumnForField(string $fieldName): string
62
    {
63 2
        foreach ($this->getColumnMaps() as $columnMap) {
64 2
            if ($columnMap->getFieldName() == $fieldName) {
65 2
                return $columnMap->getColumnName();
66
            }
67
        }
68
69
        throw new ApplicationException(
70
            sprintf("Unable to find column for `%s`", $fieldName)
71
        );
72
    }
73
}
74