Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Range
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getMin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMax
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 overlaps
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 combineWith
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15 */
16
17namespace ORES;
18
19/**
20 * Represents a range defined by two values: min and max
21 *
22 * @package ORES
23 */
24class Range {
25
26    /**
27     * @var float
28     */
29    protected $min;
30
31    /**
32     * @var float
33     */
34    protected $max;
35
36    /**
37     * @param float $min
38     * @param float $max
39     */
40    public function __construct( $min, $max ) {
41        if ( $min > $max ) {
42            throw new \DomainException( '$min must be smaller than or equal to $max' );
43        }
44        $this->min = $min;
45        $this->max = $max;
46    }
47
48    /**
49     * @return float
50     */
51    public function getMin() {
52        return $this->min;
53    }
54
55    /**
56     * @return float
57     */
58    public function getMax() {
59        return $this->max;
60    }
61
62    /**
63     * Check if the current range overlaps with or touches the given range.
64     *
65     * @param Range $other
66     * @return bool
67     */
68    public function overlaps( Range $other ) {
69        return max( $this->min, $other->min ) <= min( $this->max, $other->max );
70    }
71
72    /**
73     * Expands the current range to include the given range.
74     *
75     * @param Range $other
76     */
77    public function combineWith( Range $other ) {
78        $this->min = min( $this->min, $other->min );
79        $this->max = max( $this->max, $other->max );
80    }
81
82}