Completed
Push — master ( 7e6070...203e38 )
by Gerrit
02:38
created

EntityMapping::getEntityClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\RDMBundle\Mapping;
12
13
use Addiks\RDMBundle\Mapping\MappingInterface;
14
use Addiks\RDMBundle\Mapping\EntityMappingInterface;
15
use Doctrine\DBAL\Schema\Column;
16
17
final class EntityMapping implements EntityMappingInterface
18
{
19
20
    /**
21
     * @var string
22
     */
23
    private $className;
24
25
    /**
26
     * @var array<MappingInterface>
27
     */
28
    private $fieldMappings = array();
29
30 25
    public function __construct(string $className, array $fieldMappings)
31
    {
32 25
        $this->className = $className;
33
34 25
        foreach ($fieldMappings as $fieldName => $fieldMapping) {
35
            /** @var MappingInterface $fieldMapping */
36
37 23
            $this->addFieldMapping($fieldName, $fieldMapping);
38
        }
39 25
    }
40
41 5
    public function getEntityClassName(): string
42
    {
43 5
        return $this->className;
44
    }
45
46 12
    public function getFieldMappings(): array
47
    {
48 12
        return $this->fieldMappings;
49
    }
50
51 1
    public function describeOrigin(): string
52
    {
53 1
        return $this->className;
54
    }
55
56 10
    public function collectDBALColumns(): array
57
    {
58
        /** @var array<Column> $additionalColumns */
59 10
        $additionalColumns = array();
60
61 10
        foreach ($this->fieldMappings as $fieldMapping) {
62
            /** @var MappingInterface $fieldMapping */
63
64 10
            $additionalColumns = array_merge(
65 10
                $additionalColumns,
66 10
                $fieldMapping->collectDBALColumns()
67
            );
68
        }
69
70 10
        return $additionalColumns;
71
    }
72
73 23
    private function addFieldMapping(string $fieldName, MappingInterface $fieldMapping): void
74
    {
75 23
        $this->fieldMappings[$fieldName] = $fieldMapping;
76 23
    }
77
78
}
79