EmbeddedMapping::map()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Cascade\Mapper\Mapping;
4
5
use Cascade\Mapper\Field\Reference\ReferenceInterface;
6
use Cascade\Mapper\Map\MapInterface;
7
8
class EmbeddedMapping implements MappingInterface
9
{
10
    /**
11
     * @var ReferenceInterface
12
     */
13
    private $sourceReference;
14
15
    /**
16
     * @var MapInterface
17
     */
18
    private $map;
19
20
    /**
21
     * @param ReferenceInterface $sourceReference
22
     * @param MapInterface $map
23
     */
24 3
    public function __construct(ReferenceInterface $sourceReference, MapInterface $map)
25
    {
26 3
        $this->sourceReference = $sourceReference;
27 3
        $this->map = $map;
28 3
    }
29
30 1
    public function map($destination, $source)
31
    {
32 1
        $sourceReference = $this->sourceReference;
33 1
        $mappings = $this->map->getMappings();
34
35 1
        $embeddedValues = $sourceReference->getValue($source);
36
37 1
        $newDestination = $destination;
38 1
        foreach ($mappings as $mapping) {
39 1
            $newDestination = $mapping->map($newDestination, $embeddedValues);
40 1
        }
41
42 1
        return $newDestination;
43
    }
44
}
45