Completed
Push — master ( 2bd329...4a0c8e )
by Gaetano
18:18 queued 15:28
created

LocationMatcherDirectLoad::matchLocation()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 25
Code Lines 18

Duplication

Lines 25
Ratio 100 %

Code Coverage

Tests 17
CRAP Score 7

Importance

Changes 0
Metric Value
dl 25
loc 25
ccs 17
cts 17
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 18
nc 4
nop 1
crap 7
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\Matcher;
4
5
use Kaliop\eZMigrationBundle\API\Collection\LocationCollection;
6
7
class LocationMatcherDirectLoad extends LocationMatcher
8
{
9
    /**
10
     * Override the parent's implementation to use the repository instead of the Search Service to load Locations when
11
     * specified by Id or RemoteId.
12
     * This has the advantage of not going through Solr, and hence having less problems with transactions and indexation delay.
13
     *
14
     * @param array $conditions
15
     * @return LocationCollection
16
     */
17 11 View Code Duplication
    public function matchLocation(array $conditions)
0 ignored issues
show
Duplication introduced by
This method 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...
18
    {
19 11
        $match = reset($conditions);
20 11
        if (count($conditions) === 1 && in_array(($key = key($conditions)), array(self::MATCH_LOCATION_ID, self::MATCH_LOCATION_REMOTE_ID))) {
21 11
            $match = (array)$match;
22 11
            $locations = array();
23
            switch ($key) {
24 11
                case self::MATCH_LOCATION_ID:
25 11
                    foreach($match as $locationId) {
26 11
                        $location = $this->repository->getLocationService()->loadLocation($locationId);
27 11
                        $locations[$location->id] = $location;
28
                    }
29 11
                    break;
30 2
                case self::MATCH_LOCATION_REMOTE_ID:
31 2
                    foreach($match as $locationRemoteId) {
32 2
                        $location = $this->repository->getLocationService()->loadLocationByRemoteId($locationRemoteId);
33 2
                        $locations[$location->id] = $location;
34
                    }
35 2
                    break;
36
            }
37 11
            return new LocationCollection($locations);
38
        }
39
40 2
        return parent::matchLocation($conditions);
41
    }
42
}
43