Passed
Push — master ( 064f0a...ae02be )
by Timo
49s
created

DateRangeFacetParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 59
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 11 1
A parseRequestValue() 0 9 2
A parseResponseValue() 0 5 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\AbstractRangeFacetParser;
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
19
use ApacheSolrForTypo3\Solr\System\Data\DateTime;
20
use ApacheSolrForTypo3\Solr\System\Data\DateTimeProxy;
21
22
/**
23
 * Class DateRangeFacetParser
24
 *
25
 * @author Frans Saris <[email protected]>
26
 * @author Timo Hund <[email protected]>
27
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets
28
 */
29
class DateRangeFacetParser extends AbstractRangeFacetParser
30
{
31
    /**
32
     * @var string
33
     */
34
    protected $facetClass = DateRangeFacet::class;
35
36
    /**
37
     * @var
38
     */
39
    protected $facetItemClass = DateRange::class;
40
41
    /**
42
     * @var string
43
     */
44
    protected $facetRangeCountClass = DateRangeCount::class;
45
46
    /**
47
     * @param SearchResultSet $resultSet
48
     * @param string $facetName
49
     * @param array $facetConfiguration
50
     * @return DateRangeFacet|null
51
     */
52 2
    public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration)
53
    {
54 2
        return $this->getParsedFacet(
55
            $resultSet,
56
            $facetName,
57
            $facetConfiguration,
58 2
            $this->facetClass,
59 2
            $this->facetItemClass,
60 2
            $this->facetRangeCountClass
61
        );
62
    }
63
64
    /**
65
     * @param string $rawDate
66
     * @return DateTime|null
67
     */
68 2
    protected function parseRequestValue($rawDate)
69
    {
70 2
        $rawDate = \DateTime::createFromFormat('Ymd', substr($rawDate, 0, 8));
71 2
        if ($rawDate === false) {
72 1
            return null;
73
        }
74 1
        $date = new DateTime($rawDate->format(DateTime::ISO8601));
75 1
        return $date;
76
    }
77
78
    /**
79
     * @param string $isoDateString
80
     * @return DateTime
81
     */
82 2
    protected function parseResponseValue($isoDateString)
83
    {
84 2
        $rawDate = \DateTime::createFromFormat(\DateTime::ISO8601, $isoDateString);
85 2
        return new DateTime($rawDate->format(DateTime::ISO8601));
86
    }
87
}
88