LogicalNot::handle()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.7998
cc 3
nc 2
nop 2
1
<?php
2
3
namespace Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriterionHandler;
4
5
use eZ\Publish\API\Repository\Values\Content\Query;
6
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
7
use eZ\Publish\Core\Persistence\Database\SelectQuery;
8
use Kaliop\EzFindSearchEngineBundle\Core\Base\Exceptions\InvalidCriterionException;
9
use Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriteriaConverter;
10
use Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriterionHandler;
11
use Kaliop\EzFindSearchEngineBundle\Persistence\Solr\Content\Search\CriterionVisitor;
12
use Kaliop\EzFindSearchEngineBundle\Persistence\Solr\Content\Search\CriterionVisitorDispatcher as Dispatcher;
13
14
class LogicalNot extends CriterionHandler
15
{
16
    public function accept(Criterion $criterion)
17
    {
18
        return $criterion instanceof Criterion\LogicalNot;
19
    }
20
21
    public function handle(CriteriaConverter $converter, Criterion $criterion)
22
    {
23
        if (!isset($criterion->criteria[0]) ||
0 ignored issues
show
Bug introduced by
The property criteria does not seem to exist in eZ\Publish\API\Repositor...Content\Query\Criterion.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
24
            count($criterion->criteria) > 1
25
        ) {
26
            throw new InvalidCriterionException("LogicalNot can receive one criterion only");
27
        }
28
29
        $subfilter = (array)$converter->handle($criterion->criteria[0]);
30
        $subfilter = $converter->generateQueryString($subfilter);
31
        $result = 'NOT(' . $subfilter . ')';
32
33
        return $result;
34
    }
35
}
36