Completed
Push — master ( 2d5a04...ae10c9 )
by Gaetano
06:49
created

TrashMatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 46.51 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 20
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 4 1
A matchItem() 20 20 4

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\TrashedItemCollection;
6
use \eZ\Publish\API\Repository\Values\Content\Query;
7
8
/// q: is it better to extends Content or Location Matcher ?
9
class TrashMatcher extends ContentMatcher
10
{
11
    const MATCH_ITEM_ID = 'item_id';
12
13
    protected $returns = 'Trashed-Item';
14
15
    /**
16
     * @param array $conditions key: condition, value: int / string / int[] / string[]
17
     * @return TrashedItemCollection
18
     */
19
    public function match(array $conditions)
20
    {
21
        return $this->matchItem($conditions);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->matchItem($conditions); of type Kaliop\eZMigrationBundle...shedItemCollection|null adds the type Kaliop\eZMigrationBundle...n\TrashedItemCollection to the return on line 21 which is incompatible with the return type declared by the interface Kaliop\eZMigrationBundle...MatcherInterface::match of type array|ArrayObject.
Loading history...
22
    }
23
24
    /**
25
     * @param array $conditions
26
     * @return TrashedItemCollection
27
     *
28
     * @todo test all supported matching conditions
29
     * @todo support matching by item_id
30
     */
31 View Code Duplication
    public function matchItem(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...
32
    {
33
        $this->validateConditions($conditions);
34
35
        foreach ($conditions as $key => $values) {
36
37
            $query = new Query();
38
            $query->limit = self::INT_MAX_16BIT;
39
            if (isset($query->performCount)) $query->performCount = false;
40
            $query->filter = $this->getQueryCriterion($key, $values);
41
            $results = $this->repository->getTrashService()->findTrashItems($query);
42
43
            $items = [];
44
            foreach ($results->searchHits as $result) {
45
                $items[$result->valueObject->id] = $result->valueObject;
46
            }
47
48
            return new TrashedItemCollection($items);
49
        }
50
    }
51
}
52