-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRangeValue.php
More file actions
70 lines (54 loc) · 1.07 KB
/
RangeValue.php
File metadata and controls
70 lines (54 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php declare(strict_types = 1);
namespace Spameri\ElasticQuery\Aggregation;
class RangeValue implements \Spameri\ElasticQuery\Entity\EntityInterface
{
private string $key;
/**
* @var int|float|string|\DateTimeInterface|null
*/
private $from;
/**
* @var int|float|string|\DateTimeInterface|null
*/
private $to;
private bool $fromEqual;
private bool $toEqual;
/**
* @param int|float|string|\DateTimeInterface|null $from
* @param int|float|string|\DateTimeInterface|null $to
*/
public function __construct(
string $key,
$from,
$to,
bool $fromEqual = TRUE,
bool $toEqual = TRUE
)
{
$this->key = $key;
$this->from = $from;
$this->to = $to;
$this->fromEqual = $fromEqual;
$this->toEqual = $toEqual;
}
public function key(): string
{
return $this->key;
}
public function toArray(): array
{
$from = $this->from;
$to = $this->to;
if ( ! $this->fromEqual && \is_int($from)) {
$from++;
}
if ($this->toEqual && \is_int($to)) {
$to++;
}
return [
'key' => $this->key,
'from' => $from,
'to' => $to,
];
}
}