EmbeddedMapping::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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