Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
36.36% covered (danger)
36.36%
4 / 11
25.00% covered (danger)
25.00%
1 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
IntegerOrNullOption
36.36% covered (danger)
36.36%
4 / 11
25.00% covered (danger)
25.00%
1 / 4
15.28
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 check
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
2.26
 getValueForPrint
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getDefinition
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace WebPConvert\Options;
4
5use WebPConvert\Options\IntegerOption;
6use WebPConvert\Options\Exceptions\InvalidOptionValueException;
7
8/**
9 * Abstract option class
10 *
11 * @package    WebPConvert
12 * @author     Bjørn Rosell <it@rosell.dk>
13 * @since      Class available since Release 2.0.0
14 */
15class IntegerOrNullOption extends IntegerOption
16{
17    protected $schemaType = ['integer', 'null'];
18
19    public function __construct($id, $defaultValue, $minValue = null, $maxValue = null)
20    {
21        parent::__construct($id, $defaultValue, $minValue, $maxValue);
22    }
23
24    public function check()
25    {
26        $this->checkMinMax();
27
28        $valueType = gettype($this->getValue());
29        if (!in_array($valueType, ['integer', 'NULL'])) {
30            throw new InvalidOptionValueException(
31                'The "' . $this->id . '" option must be either integer or NULL. ' .
32                    'You however provided a value of type: ' . $valueType
33            );
34        }
35    }
36
37    public function getValueForPrint()
38    {
39        if (gettype($this->getValue() == 'NULL')) {
40            return 'null (not set)';
41        }
42        return parent::getValueForPrint();
43    }
44
45    public function getDefinition()
46    {
47        $obj = parent::getDefinition();
48        return $obj;
49    }
50}