Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
42.86% |
6 / 14 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
QualityOption | |
42.86% |
6 / 14 |
|
33.33% |
1 / 3 |
24.11 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
check | |
50.00% |
5 / 10 |
|
0.00% |
0 / 1 |
10.50 | |||
getValueForPrint | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
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 <it@rosell.dk> |
15 | * @since Class available since Release 2.0.0 |
16 | */ |
17 | class QualityOption extends Option |
18 | { |
19 | protected $typeId = 'int'; |
20 | protected $schemaType = ['integer', 'string']; |
21 | |
22 | public function __construct($id, $defaultValue) |
23 | { |
24 | parent::__construct($id, $defaultValue); |
25 | } |
26 | |
27 | public function check() |
28 | { |
29 | $value = $this->getValue(); |
30 | if (gettype($value) == 'string') { |
31 | if ($value != 'auto') { |
32 | throw new InvalidOptionValueException( |
33 | 'The "quality" option must be either "auto" or a number between 0-100. ' . |
34 | 'A string, different from "auto" was given' |
35 | ); |
36 | } |
37 | } elseif (gettype($value) == 'integer') { |
38 | if (($value < 0) || ($value > 100)) { |
39 | throw new InvalidOptionValueException( |
40 | 'The "quality" option must be either "auto" or a number between 0-100. ' . |
41 | 'The number you provided (' . strval($value) . ') is out of range.' |
42 | ); |
43 | } |
44 | } else { |
45 | throw new InvalidOptionValueException( |
46 | 'The "quality" option must be either "auto" or an integer. ' . |
47 | 'You however provided a value of type: ' . gettype($value) |
48 | ); |
49 | } |
50 | } |
51 | |
52 | public function getValueForPrint() |
53 | { |
54 | if (gettype($this->getValue()) == 'string') { |
55 | return '"' . $this->getValue() . '"'; |
56 | } |
57 | return $this->getValue(); |
58 | } |
59 | } |