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

TrashMatcher::match()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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