Passed
Pull Request — release-11.2.x (#3604)
by Markus
32:12 queued 27:55
created

DateRangeFacetParser::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\DateRange;
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacet;
19
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\AbstractRangeFacetParser;
20
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
21
use ApacheSolrForTypo3\Solr\System\Data\DateTime;
22
23
/**
24
 * Class DateRangeFacetParser
25
 *
26
 * @author Frans Saris <[email protected]>
27
 * @author Timo Hund <[email protected]>
28
 */
29
class DateRangeFacetParser extends AbstractRangeFacetParser
30
{
31
    /**
32
     * @var string
33
     */
34
    protected $facetClass = DateRangeFacet::class;
35
36
    /**
37
     * @var string
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 AbstractFacet|null
51
     */
52 1
    public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration)
53
    {
54 1
        return $this->getParsedFacet(
55
            $resultSet,
56
            $facetName,
57
            $facetConfiguration,
58 1
            $this->facetClass,
59 1
            $this->facetItemClass,
60 1
            $this->facetRangeCountClass
61
        );
62
    }
63
64
    /**
65
     * @param string $rawDate
66
     * @return DateTime|null
67
     */
68 1
    protected function parseRequestValue($rawDate)
69
    {
70 1
        $rawDate = \DateTime::createFromFormat('Ymd', substr($rawDate, 0, 8));
71 1
        if ($rawDate === false) {
72
            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 1
    protected function parseResponseValue($isoDateString)
83
    {
84 1
        $rawDate = \DateTime::createFromFormat(\DateTime::ISO8601, $isoDateString);
85 1
        return new DateTime($rawDate->format(DateTime::ISO8601));
86
    }
87
}
88