PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.3
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 / QualityOption.php

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

60 lines 1.8 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 * 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 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 }
60