Passed
Push — release-11.0.x ( 181948...809732 )
by Rafael
28:42 queued 25:26
created

DateRange   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 54.29%

Importance

Changes 0
Metric Value
wmc 10
eloc 22
dl 0
loc 99
ccs 19
cts 35
cp 0.5429
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 3
A getRangeString() 0 5 3
A getEndInResponse() 0 3 1
A getEndRequested() 0 3 1
A getStartRequested() 0 3 1
A getStartInResponse() 0 3 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\AbstractRangeFacetItem;
18
use DateTime;
19
20
/**
21
 * Value object that represent an option of a options facet.
22
 *
23
 * @author Frans Saris <[email protected]>
24
 * @author Timo Hund <[email protected]>
25
 */
26
class DateRange extends AbstractRangeFacetItem
27
{
28
    /**
29
     * @var DateTime
30
     */
31
    protected $startRequested;
32
33
    /**
34
     * @var DateTime
35
     */
36
    protected $endRequested;
37
38
    /**
39
     * @var DateTime
40
     */
41
    protected $startInResponse;
42
43
    /**
44
     * @var DateTime
45
     */
46
    protected $endInResponse;
47
48
    /**
49
     * @param DateRangeFacet $facet
50
     * @param DateTime|null $startRequested
51
     * @param DateTime|null $endRequested
52
     * @param DateTime|null $startInResponse
53
     * @param DateTime|null $endInResponse
54
     * @param string $gap
55
     * @param int $documentCount
56
     * @param array $rangeCounts
57
     * @param bool $selected
58
     */
59 1
    public function __construct(DateRangeFacet $facet, DateTime $startRequested = null, DateTime $endRequested = null, DateTime $startInResponse = null, DateTime $endInResponse = null, $gap = '', $documentCount = 0, $rangeCounts, $selected = false)
60
    {
61 1
        $this->startInResponse = $startInResponse;
62 1
        $this->endInResponse = $endInResponse;
63 1
        $this->startRequested = $startRequested;
64 1
        $this->endRequested = $endRequested;
65 1
        $this->rangeCounts = $rangeCounts;
66 1
        $this->gap = $gap;
67
68 1
        $label = '';
69 1
        if ($startRequested instanceof DateTime && $endRequested instanceof DateTime) {
70
            $label = $this->getRangeString();
71
        }
72
73
74 1
        parent::__construct($facet, $label, $documentCount, $selected);
75 1
    }
76
77
    /**
78
     * @return string
79
     */
80
    protected function getRangeString()
81
    {
82
        $from = null === $this->startRequested ? '' : $this->startRequested->format('Ymd') . '0000';
83
        $till = null === $this->endRequested ? '' : $this->endRequested->format('Ymd') . '0000';
84
        return $from . '-' . $till;
85
    }
86
87
    /**
88
     * Retrieves the end date that was requested by the user for this facet.
89
     *
90
     * @return \DateTime
91
     */
92 1
    public function getEndRequested()
93
    {
94 1
        return $this->endRequested;
95
    }
96
97
    /**
98
     * Retrieves the start date that was requested by the used for the facet.
99
     *
100
     * @return \DateTime
101
     */
102 1
    public function getStartRequested()
103
    {
104 1
        return $this->startRequested;
105
    }
106
107
    /**
108
     * Retrieves the end date that was received from solr for this facet.
109
     *
110
     * @return \DateTime
111
     */
112 1
    public function getEndInResponse()
113
    {
114 1
        return $this->endInResponse;
115
    }
116
117
    /**
118
     * Retrieves the start date that was received from solr for this facet.
119
     *
120
     * @return \DateTime
121
     */
122 1
    public function getStartInResponse()
123
    {
124 1
        return $this->startInResponse;
125
    }
126
}
127