Completed
Pull Request — master (#93)
by
unknown
23:15
created

EzRelationList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createValue() 0 21 4
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\ComplexField;
4
5
use eZ\Publish\Core\FieldType\RelationList\Value;
6
use Kaliop\eZMigrationBundle\API\ComplexFieldInterface;
7
use Kaliop\eZMigrationBundle\Core\Matcher\ContentMatcher;
8
9
class EzRelationList extends AbstractComplexField implements ComplexFieldInterface
10
{
11
    protected $contentMatcher;
12
13
    public function __construct(ContentMatcher $contentMatcher)
14
    {
15 1
        $this->contentMatcher = $contentMatcher;
16
    }
17 1
18
    /**
19 1
     * @param array $fieldValueArray The definition of the field value, structured in the yml file
20 1
     * @param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
21
     * @return Value
22 1
     */
23
    public function createValue($fieldValueArray, array $context = array())
24
    {
25 1
        if (array_key_exists('destinationContentIds', $fieldValueArray)) {
26 1
            // fromHash format
27 1
            $ids = $fieldValueArray['destinationContentIds'];
28 1
        } elseif (is_array($fieldValueArray)) {
29 1
            // simplified format
30
            $ids = $fieldValueArray;
31 1
        } else {
32
            $ids = array();
33
        }
34
35
        foreach ($ids as $key => $id) {
36
            // 1. resolve relations
37
            $ids[$key] = $this->referenceResolver->resolveReference($id);
38
            // 2. resolve remote ids
39
            $ids[$key] = $this->contentMatcher->matchOneByKey($ids[$key])->id;
40
        }
41
42
        return new Value($ids);
43
    }
44
}
45