PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / webp-convert / src / Options / IntegerOption.php

IntegerOption.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at vendor/rosell-dk/webp-convert/src/Options/IntegerOption.php

77 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 IntegerOption extends Option
16 {
17 protected $typeId = 'int';
18 protected $schemaType = ['integer'];
19 protected $minValue;
20 protected $maxValue;
21
22 /**
23 * Constructor.
24 *
25 * @param string $id id of the option
26 * @param integer $defaultValue default value for the option
27 * @throws InvalidOptionValueException if the default value cannot pass the check
28 * @return void
29 */
30 public function __construct($id, $defaultValue, $minValue = null, $maxValue = null)
31 {
32 $this->minValue = $minValue;
33 $this->maxValue = $maxValue;
34 parent::__construct($id, $defaultValue);
35 }
36
37 protected function checkMin()
38 {
39 if (!is_null($this->minValue) && $this->getValue() < $this->minValue) {
40 throw new InvalidOptionValueException(
41 '"' . $this->id . '" option must be set to minimum ' . $this->minValue . '. ' .
42 'It was however set to: ' . $this->getValue()
43 );
44 }
45 }
46
47 protected function checkMax()
48 {
49 if (!is_null($this->maxValue) && $this->getValue() > $this->maxValue) {
50 throw new InvalidOptionValueException(
51 '"' . $this->id . '" option must be set to max ' . $this->maxValue . '. ' .
52 'It was however set to: ' . $this->getValue()
53 );
54 }
55 }
56
57 protected function checkMinMax()
58 {
59 $this->checkMin();
60 $this->checkMax();
61 }
62
63 public function check()
64 {
65 $this->checkType('integer');
66 $this->checkMinMax();
67 }
68
69 public function getSchema()
70 {
71 $obj = parent::getSchema();
72 $obj['minimum'] = $this->minValue;
73 $obj['maximum'] = $this->maxValue;
74 return $obj;
75 }
76 }
77