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

StringOption::check()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 0
dl 0
loc 9
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 StringOption extends Option
16
{
17
18
    public $allowedValues;
19
20
    public function __construct($id, $defaultValue, $allowedValues = null)
21
    {
22
        $this->allowedValues = $allowedValues;
23
        parent::__construct($id, $defaultValue);
24
    }
25
26
    public function check()
27
    {
28
        $this->checkType('string');
29
30
        if (!is_null($this->allowedValues) && (!in_array($this->getValue(), $this->allowedValues))) {
31
            throw new InvalidOptionValueException(
32
                '"' . $this->id . '" option must be on of these values: ' .
33
                '[' . implode(', ', $this->allowedValues) . ']. ' .
34
                'It was however set to: "' . $this->getValue() . '"'
35
            );
36
        }
37
    }
38
}
39