Passed
Push — master ( 2b8f81...145d48 )
by Gaetano
10:22 queued 05:19
created

LocationResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 31
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getReferenceValue() 0 7 2
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\ReferenceResolver;
4
5
use Kaliop\eZMigrationBundle\Core\Matcher\LocationMatcher;
6
7
/**
8
 * Handles references to locations. At the moment: supports remote Ids.
9
 *
10
 * @todo drop support for 'location:' in favour of 'location_remote_id:'
11
 */
12
class LocationResolver extends AbstractResolver
13
{
14
    /**
15
     * Defines the prefix for all reference identifier strings in definitions
16
     */
17
    protected $referencePrefixes = array('location:' /*, 'location_remote_id:'*/);
18
19
    protected $locationMatcher;
20
21
    /**
22
     * @param LocationMatcher $locationMatcher
23
     */
24
    public function __construct(LocationMatcher $locationMatcher)
25
    {
26
        parent::__construct();
27
28
        $this->locationMatcher = $locationMatcher;
29
    }
30
31
    /**
32
     * @param $stringIdentifier location:<remote_id>
33
     * @return string Location id
34
     * @throws \Exception
35
     */
36
    public function getReferenceValue($stringIdentifier)
37
    {
38
        $ref = $this->getReferenceIdentifierByPrefix($stringIdentifier);
39
        switch ($ref['prefix']) {
40
            // deprecated tag: 'location:'
41
            case 'location:':
42
                return $this->locationMatcher->MatchOne(array(LocationMatcher::MATCH_LOCATION_REMOTE_ID => $ref['identifier']))->id;
43
            //case 'location_remote_id:':
44
            //    return $this->repository->getLocationService()->loadLocationByRemoteId($ref['identifier'])->id;
45
        }
46
    }
47
}
48