Passed
Push — main ( c49c6c...49fc69 )
by Gaetano
08:47
created

ReferenceResolverTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveReference() 0 3 1
A resolveReferencesRecursively() 0 9 3
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\Executor;
4
5
use Kaliop\eZMigrationBundle\API\Collection\AbstractCollection;
6
use Kaliop\eZMigrationBundle\API\Exception\InvalidMatchResultsNumberException;
7
use Kaliop\eZMigrationBundle\API\Exception\InvalidStepDefinitionException;
8
use Kaliop\eZMigrationBundle\API\ReferenceResolverInterface;
9
use Kaliop\eZMigrationBundle\API\Value\MigrationStep;
10
11
/**
12
 * A trait, used by Executors, which has code useful to resolve references
13
 */
14
trait ReferenceResolverTrait
15
{
16
    /** @var ReferenceResolverInterface */
17
    protected $referenceResolver;
18
19
    protected function resolveReference($identifier)
20
    {
21
        return $this->referenceResolver->resolveReference($identifier);
22
    }
23
24
    /**
25
     * @todo should be moved into the reference resolver classes
26
     */
27
    protected function resolveReferencesRecursively($value)
28
    {
29
        if (is_array($value)) {
30
            foreach ($value as $key => $values) {
31
                $value[$key] = $this->resolveReferencesRecursively($values);
32
            }
33
            return $value;
34
        } else {
35
            return $this->resolveReference($value);
36
        }
37
    }
38
}
39