Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Range
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 getMin
n/a
0 / 0
n/a
0 / 0
0
 getMax
n/a
0 / 0
n/a
0 / 0
0
 setRange
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 getRange
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isInRange
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * @author: Doug Wilbourne (dougwilbourne@gmail.com)
5 */
6
7declare(strict_types=1);
8
9namespace pvc\struct\range;
10
11use pvc\interfaces\struct\range\RangeInterface;
12
13/**
14 * @class Range
15 *
16 * The class provides methods for creating a range, getting a range as an array, checking if a payload is in the range.
17 *
18 * @template RangeElementDataType
19 * @implements RangeInterface<RangeElementDataType>
20 */
21abstract class Range implements RangeInterface
22{
23    /**
24     * @var RangeElementDataType|null
25     */
26    protected $min;
27
28    /**
29     * @var RangeElementDataType|null
30     */
31    protected $max;
32
33    /**
34     * getMin
35     * @return RangeElementDataType
36     */
37    abstract protected function getMin(): mixed;
38
39    /**
40     * getMax
41     * @return RangeElementDataType
42     */
43    abstract protected function getMax(): mixed;
44
45    /**
46     * @param RangeElementDataType $min
47     * @param RangeElementDataType $max
48     */
49    public function setRange($min, $max): void
50    {
51        $this->min = ($min < $max) ? $min : $max;
52        $this->max = ($min < $max) ? $max : $min;
53    }
54
55    /**
56     * getRange
57     * @return array<RangeElementDataType>
58     */
59    public function getRange(): array
60    {
61        return [$this->getMin(), $this->getMax()];
62    }
63
64    /**
65     * isInRange
66     * @param RangeElementDataType $x
67     * @return bool
68     */
69    public function isInRange($x): bool
70    {
71        return (($this->getMin() <= $x) && ($x <= $this->getMax()));
72    }
73}