Completed
Push — master ( 203e38...2cdd54 )
by Gerrit
13:04
created

FieldValueResolver::resolveValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 3
crap 3
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\ValueResolver;
14
15
use Addiks\RDMBundle\ValueResolver\ValueResolverInterface;
16
use Addiks\RDMBundle\Mapping\MappingInterface;
17
use Addiks\RDMBundle\Mapping\FieldMappingInterface;
18
use Doctrine\DBAL\Schema\Column;
19
use Addiks\RDMBundle\Exception\FailedRDMAssertionException;
20
21
final class FieldValueResolver implements ValueResolverInterface
22
{
23
24 2
    public function resolveValue(
25
        MappingInterface $fieldMapping,
26
        $entity,
27
        array $dataFromAdditionalColumns
28
    ) {
29
        /** @var mixed $value */
30 2
        $value = null;
31
32 2
        if ($fieldMapping instanceof FieldMappingInterface) {
33
            /** @var Column $dbalColumn */
34 2
            $dbalColumn = $fieldMapping->getDBALColumn();
35
36
            # TODO: use doctrine's field to value mapping system here (whatever that is)
37 2
            if (isset($dataFromAdditionalColumns[$dbalColumn->getName()])) {
38 2
                $value = $dataFromAdditionalColumns[$dbalColumn->getName()];
39
            }
40
        }
41
42 2
        return $value;
43
    }
44
45 2
    public function revertValue(
46
        MappingInterface $fieldMapping,
47
        $entity,
48
        $valueFromEntityField
49
    ): array {
50
        /** @var mixed $data */
51 2
        $data = array();
52
53 2
        if ($fieldMapping instanceof FieldMappingInterface) {
54
            /** @var Column $dbalColumn */
55 2
            $dbalColumn = $fieldMapping->getDBALColumn();
56
57
            # TODO: use doctrine's field to value mapping system here (whatever that is)
58 2
            $data[$dbalColumn->getName()] = $valueFromEntityField;
59
        }
60
61 2
        return $data;
62
    }
63
64 1
    public function assertValue(
65
        MappingInterface $fieldMapping,
66
        $entity,
67
        array $dataFromAdditionalColumns,
68
        $actualValue
69
    ): void {
70 1
    }
71
72
}
73