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

QualityOption::check()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 5
nop 0
dl 0
loc 21
rs 9.2222
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
 * Quality option.
10
 *
11
 * Quality can be a number between 0-100 or "auto"
12
 *
13
 * @package    WebPConvert
14
 * @author     Bjørn Rosell <[email protected]>
15
 * @since      Class available since Release 2.0.0
16
 */
17
class QualityOption extends Option
18
{
19
20
    public function __construct($id, $defaultValue)
21
    {
22
        parent::__construct($id, $defaultValue);
23
    }
24
25
    public function check()
26
    {
27
        $value = $this->getValue();
28
        if (gettype($value) == 'string') {
29
            if ($value != 'auto') {
30
                throw new InvalidOptionValueException(
31
                    'The "quality" option must be either "auto" or a number between 0-100. ' .
32
                    'A string, different from "auto" was given'
33
                );
34
            }
35
        } elseif (gettype($value) == 'integer') {
36
            if (($value < 0) || ($value > 100)) {
37
                throw new InvalidOptionValueException(
38
                    'The "quality" option must be either "auto" or a number between 0-100. ' .
39
                        'The number you provided (' . strval($value) . ') is out of range.'
40
                );
41
            }
42
        } else {
43
            throw new InvalidOptionValueException(
44
                'The "quality" option must be either "auto" or an integer. ' .
45
                    'You however provided a value of type: ' . gettype($value)
46
            );
47
        }
48
    }
49
}
50