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

LocationMatcherDirectLoad   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 72.22 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 26
loc 36
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C matchLocation() 25 25 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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