Test Failed
Push — master ( 975525...307699 )
by Bjørn
02:39
created

IntegerOption::check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebPConvert\Options;
4
5
use WebPConvert\Options\Option;
6
use WebPConvert\Options\Exceptions\InvalidOptionValueException;
7
8
/**
9
 * Abstract option class
10
 *
11
 * @package    WebPConvert
12
 * @author     Bjørn Rosell <[email protected]>
13
 * @since      Class available since Release 2.0.0
14
 */
15
class IntegerOption extends Option
16
{
17
18
    protected $minValue;
19
    protected $maxValue;
20
21
    public function __construct($id, $defaultValue, $minValue = null, $maxValue = null)
22
    {
23
        $this->minValue = $minValue;
24
        $this->maxValue = $maxValue;
25
        parent::__construct($id, $defaultValue);
26
    }
27
28
    protected function checkMin()
29
    {
30
        if (!is_null($this->minValue) && $this->getValue() < $this->minValue) {
31
            throw new InvalidOptionValueException(
32
                '"' . $this->id . '" option must be set to minimum ' . $this->minValue . '. ' .
33
                'It was however set to: ' . $this->getValue()
34
            );
35
        }
36
    }
37
38
    protected function checkMax()
39
    {
40
        if (!is_null($this->maxValue) && $this->getValue() > $this->maxValue) {
41
            throw new InvalidOptionValueException(
42
                '"' . $this->id . '" option must be set to max ' . $this->maxValue . '. ' .
43
                'It was however set to: ' . $this->getValue()
44
            );
45
        }
46
    }
47
48
    protected function checkMinMax()
49
    {
50
        $this->checkMin();
51
        $this->checkMax();
52
    }
53
54
    public function check()
55
    {
56
        $this->checkType('integer');
57
        $this->checkMinMax();
58
    }
59
}
60