Completed
Push — master ( 12f48c...b47ac0 )
by Gaetano
06:59
created

EzRelationList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 26
rs 10
wmc 5
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B createValue() 0 18 5
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
8
class EzRelationList extends AbstractComplexField implements ComplexFieldInterface
9
{
10
    /**
11
     * @param array $fieldValueArray The definition of the field value, structured in the yml file
12
     * @param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
13
     * @return PageValue
14
     */
15
    public function createValue(array $fieldValueArray, array $context = array())
16
    {
17
        if (count($fieldValueArray) == 1 && isset($fieldValueArray['destinationContentIds'])) {
18
            // fromHash format
19
            $ids = $fieldValueArray['destinationContentIds'];
20
        } else {
21
            // simplified format
22
            $ids = $fieldValueArray;
23
        }
24
25
        foreach ($ids as $key => $id) {
26
            if ($this->referenceResolver->isReference($id)) {
27
                $ids[$key] = $this->referenceResolver->getReferenceValue($id);
28
            }
29
        }
30
31
        return new Value($ids);
32
    }
33
}
34