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

IntegerOrNullOption   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace WebPConvert\Options;
4
5
use WebPConvert\Options\IntegerOption;
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 IntegerOrNullOption extends IntegerOption
16
{
17
18
    public function __construct($id, $defaultValue, $minValue = null, $maxValue = null)
19
    {
20
        parent::__construct($id, $defaultValue, $minValue, $maxValue);
21
    }
22
23
    public function check()
24
    {
25
        $this->checkMinMax();
26
27
        $valueType = gettype($this->getValue());
28
        if (!in_array($valueType, ['integer', 'NULL'])) {
29
            throw new InvalidOptionValueException(
30
                'The "' . $this->id . '" option must be either integer or NULL. ' .
31
                    'You however provided a value of type: ' . $valueType
32
            );
33
        }
34
    }
35
}
36