DateMetadata::accept()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
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\Criterion;
6
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;
7
use Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriteriaConverter;
8
use Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriterionHandler;
9
10
class DateMetadata extends CriterionHandler
11
{
12
    public function accept( Criterion $criterion )
13
    {
14
        return $criterion instanceof Criterion\DateMetadata;
15
    }
16
17
    public function handle( CriteriaConverter $converter, Criterion $criterion )
18
    {
19
        $field = $criterion->target == Criterion\DateMetadata::MODIFIED ? 'modified' : 'published';
20
21
        switch ( $criterion->operator )
22
        {
23 View Code Duplication
            case Criterion\Operator::BETWEEN:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
24
                return $field . ':[' . $this->formatDate($criterion->value[0]) . ' TO ' . $this->formatDate($criterion->value[1]) . ']';
25
26 View Code Duplication
            case Criterion\Operator::GT:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
27
                return $field . ':{' . $this->formatDate(reset($criterion->value)) . ' TO *]';
28
29 View Code Duplication
            case Criterion\Operator::GTE:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
30
                return $field . ':[' . $this->formatDate(reset($criterion->value)) . ' TO *]';
31
32 View Code Duplication
            case Criterion\Operator::LT:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
33
                return $field . ':[* TO ' . $this->formatDate(reset($criterion->value)) . '}';
34
35 View Code Duplication
            case Criterion\Operator::LTE:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
                return $field . ':[* TO ' . $this->formatDate(reset($criterion->value)) . ']';
37
38
            /// @todo this currently breaks solr
39 View Code Duplication
            case Criterion\Operator::IN:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
40
                $values = array_map(array($this, 'formatDate'), $criterion->value);
41
                return $field . ':(' . implode(' ', $values) . ')';
42
        }
43
    }
44
}
45