Completed
Push — master ( dde077...2d5a04 )
by Gaetano
09:15
created

LocationMatcherDirectLoad::matchLocation()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 23
Code Lines 16

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
dl 23
loc 23
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 16
nc 4
nop 1
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 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
        $match = reset($conditions);
20
        if (count($conditions) === 1 && in_array(($key = key($conditions)), array(self::MATCH_LOCATION_ID, self::MATCH_LOCATION_REMOTE_ID))) {
21
            $match = (array)$match;
22
            $locations = array();
23
            switch ($key) {
24
                case self::MATCH_LOCATION_ID:
25
                    foreach($match as $locationId) {
26
                        $locations[] = $this->repository->getLocationService()->loadLocation($locationId);
27
                    }
28
                    break;
29
                case self::MATCH_LOCATION_REMOTE_ID:
30
                    foreach($match as $locationRemoteId) {
31
                        $locations[] = $this->repository->getLocationService()->loadLocationByRemoteId($locationRemoteId);
32
                    }
33
                    break;
34
            }
35
            return new LocationCollection($locations);
36
        }
37
38
        return parent::matchLocation($conditions);
39
    }
40
}
41