SortClauseConverter::canHandle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.9
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway;
4
5
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
6
use Kaliop\EzFindSearchEngineBundle\Core\Base\Exceptions\NotImplementedException;
7
8
class SortClauseConverter extends Converter
9
{
10
    /**
11
     * @param SortClause $sortClause
12
     * @return bool
13
     */
14
    public function canHandle(SortClause $sortClause)
15
    {
16
        /** @var SortClauseHandler $handler */
17
        foreach ($this->handlers as $handler) {
18
            if ($handler->accept($sortClause)) {
19
                return true;
20
            }
21
        }
22
23
        return false;
24
    }
25
26
    /**
27
     * @param SortClause $sortClause
28
     * @return array
29
     * @throws NotImplementedException
30
     */
31 View Code Duplication
    public function handle(SortClause $sortClause)
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
        /** @var SortClauseHandler $handler */
34
        foreach ($this->handlers as $handler) {
35
            if ($handler->accept($sortClause)) {
36
                return $handler->handle($sortClause);
37
            }
38
        }
39
40
        throw new NotImplementedException(
41
            'No handler available for: ' . get_class($sortClause) . ' with direction ' . $sortClause->direction
42
        );
43
    }
44
}
45