Passed
Pull Request — master (#1318)
by
unknown
32:46
created

DateRangeFacetParser::parseResponseValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 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
    public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration)
53
    {
54
        return $this->getParsedFacet(
55
            $resultSet,
56
            $facetName,
57
            $facetConfiguration,
58
            $this->facetClass,
59
            $this->facetItemClass,
60
            $this->facetRangeCountClass
61
        );
62
    }
63
64
    /**
65
     * @param string $rawDate
66
     * @return DateTime|null
67
     */
68
    protected function parseRequestValue($rawDate)
69
    {
70
        $rawDate = \DateTime::createFromFormat('Ymd', substr($rawDate, 0, 8));
71
        if ($rawDate === false) {
72
            return null;
73
        }
74
        $date = new DateTime($rawDate->format(DateTime::ISO8601));
75
        return $date;
76
    }
77
78
    /**
79
     * @param string $isoDateString
80
     * @return DateTime
81
     */
82
    protected function parseResponseValue($isoDateString)
83
    {
84
        $rawDate = \DateTime::createFromFormat(\DateTime::ISO8601, $isoDateString);
85
        return new DateTime($rawDate->format(DateTime::ISO8601));
86
    }
87
}
88