Passed
Push — release-11.2.x ( 9027bf...093924 )
by Markus
12:13
created

DateRangeFacetParser::parseResponseValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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\Domain\Search\ResultSet\Facets\AbstractFacet;
21
22
/**
23
 * Class DateRangeFacetParser
24
 *
25
 * @author Frans Saris <[email protected]>
26
 * @author Timo Hund <[email protected]>
27
 */
28
class DateRangeFacetParser extends AbstractRangeFacetParser
29
{
30
    /**
31
     * @var string
32
     */
33
    protected $facetClass = DateRangeFacet::class;
34
35
    /**
36
     * @var string
37
     */
38
    protected $facetItemClass = DateRange::class;
39
40
    /**
41
     * @var string
42
     */
43
    protected $facetRangeCountClass = DateRangeCount::class;
44
45
    /**
46
     * @param SearchResultSet $resultSet
47
     * @param string $facetName
48
     * @param array $facetConfiguration
49
     * @return AbstractFacet|null
50
     */
51 1
    public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration)
52
    {
53 1
        return $this->getParsedFacet(
54 1
            $resultSet,
55
            $facetName,
56
            $facetConfiguration,
57 1
            $this->facetClass,
58 1
            $this->facetItemClass,
59 1
            $this->facetRangeCountClass
60
        );
61
    }
62
63
    /**
64
     * @param string $rawDate
65
     * @return DateTime|null
66
     */
67 1
    protected function parseRequestValue($rawDate)
68
    {
69 1
        $rawDate = \DateTime::createFromFormat('Ymd', substr($rawDate, 0, 8));
70 1
        if ($rawDate === false) {
71
            return null;
72
        }
73 1
        $date = new DateTime($rawDate->format(DateTime::ISO8601));
74 1
        return $date;
75
    }
76
77
    /**
78
     * @param string $isoDateString
79
     * @return DateTime
80
     */
81 1
    protected function parseResponseValue($isoDateString)
82
    {
83 1
        $rawDate = \DateTime::createFromFormat(\DateTime::ISO8601, $isoDateString);
84 1
        return new DateTime($rawDate->format(DateTime::ISO8601));
85
    }
86
}
87