MappingProxy::resolveValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
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
 *
8
 * @license GPL-3.0
9
 *
10
 * @author Gerrit Addiks <[email protected]>
11
 */
12
13
namespace Addiks\RDMBundle\Mapping;
14
15
use Addiks\RDMBundle\Mapping\MappingInterface;
16
use Addiks\RDMBundle\Hydration\HydrationContextInterface;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
use Doctrine\DBAL\Schema\Column;
19
20
final class MappingProxy implements MappingInterface
21
{
22
23
    /**
24
     * @var MappingInterface
25
     */
26
    private $innerMapping;
27
28
    /**
29
     * @var string
30
     */
31
    private $columnPrefix;
32
33 7
    public function __construct(
34
        MappingInterface $innerMapping,
35
        string $columnPrefix
36
    ) {
37 7
        $this->innerMapping = $innerMapping;
38 7
        $this->columnPrefix = $columnPrefix;
39
    }
40
41 1
    public function describeOrigin(): string
42
    {
43 1
        return $this->innerMapping->describeOrigin();
44
    }
45
46 1
    public function collectDBALColumns(): array
47
    {
48
        /** @var array<Column> $dbalColumns */
49 1
        $dbalColumns = $this->innerMapping->collectDBALColumns();
50
51
        /** @var array<Column> $prefixedColumns */
52 1
        $prefixedColumns = array();
53
54 1
        foreach ($dbalColumns as $key => $column) {
55
            /** @var Column $column */
56
57 1
            $prefixedColumns[$key] = new Column(
58 1
                sprintf("%s%s", $this->columnPrefix, $column->getName()),
59 1
                $column->getType(),
60 1
                $column->toArray()
61
            );
62
        }
63
64 1
        return $prefixedColumns;
65
    }
66
67 1
    public function resolveValue(
68
        HydrationContextInterface $context,
69
        array $dataFromAdditionalColumns
70
    ) {
71 1
        return $this->innerMapping->resolveValue($context, $dataFromAdditionalColumns);
72
    }
73
74 1
    public function revertValue(
75
        HydrationContextInterface $context,
76
        $valueFromEntityField
77
    ): array {
78 1
        return $this->innerMapping->revertValue($context, $valueFromEntityField);
79
    }
80
81 1
    public function assertValue(
82
        HydrationContextInterface $context,
83
        array $dataFromAdditionalColumns,
84
        $actualValue
85
    ): void {
86 1
        $this->innerMapping->assertValue($context, $dataFromAdditionalColumns, $actualValue);
87
    }
88
89 1
    public function wakeUpMapping(ContainerInterface $container): void
90
    {
91 1
        $this->innerMapping->wakeUpMapping($container);
92
    }
93
94
}
95