Completed
Pull Request — master (#133)
by Damian
20:49 queued 18:16
created

LocationResolver::getReferenceValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.0185
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 View Code Duplication
class LocationResolver extends AbstractResolver
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 70
    public function __construct(LocationMatcher $locationMatcher)
25
    {
26 70
        parent::__construct();
27
28 70
        $this->locationMatcher = $locationMatcher;
29 70
    }
30
31
    /**
32
     * @param $stringIdentifier location:<remote_id>
33
     * @return string Location id
34
     * @throws \Exception
35
     */
36 1
    public function getReferenceValue($stringIdentifier)
37
    {
38 1
        $ref = $this->getReferenceIdentifierByPrefix($stringIdentifier);
39 1
        switch ($ref['prefix']) {
40
            // deprecated tag: 'location:'
41 1
            case 'location:':
42 1
                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;
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
        }
46
    }
47
}
48