Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Quality | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| perform | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Karla ImageMagick wrapper library |
| 5 | * |
| 6 | * PHP Version 8.0< |
| 7 | * |
| 8 | * @category Utility |
| 9 | * @author Johannes Skov Frandsen <jsf@greenoak.dk> |
| 10 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
| 11 | * @link https://github.com/localgod/karla Karla |
| 12 | * @since 2013-05-26 |
| 13 | */ |
| 14 | |
| 15 | declare(strict_types=1); |
| 16 | |
| 17 | namespace Karla\Action; |
| 18 | |
| 19 | use Karla\Query; |
| 20 | use Karla\Action; |
| 21 | |
| 22 | /** |
| 23 | * Class for handeling quality action |
| 24 | * |
| 25 | * @category Utility |
| 26 | * @author Johannes Skov Frandsen <jsf@greenoak.dk> |
| 27 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
| 28 | * @link https://github.com/localgod/karla Karla |
| 29 | */ |
| 30 | class Quality implements Action |
| 31 | { |
| 32 | /** |
| 33 | * The quality to use |
| 34 | * |
| 35 | * @var integer |
| 36 | */ |
| 37 | private int $quality; |
| 38 | |
| 39 | /** |
| 40 | * The format to use |
| 41 | * |
| 42 | * @var string |
| 43 | */ |
| 44 | private string $format; |
| 45 | |
| 46 | /** |
| 47 | * Construct a new quality action |
| 48 | * |
| 49 | * @param integer $quality |
| 50 | * Quality |
| 51 | * @param string $format |
| 52 | * Format |
| 53 | * |
| 54 | * @throws \InvalidArgumentException |
| 55 | * @throws \RangeException |
| 56 | */ |
| 57 | public function __construct(int $quality, string $format) |
| 58 | { |
| 59 | if (! preg_match('/^jpeg|jpg|png$/', $format)) { |
| 60 | $message = "'quality()' is only supported for the jpeg and png format. Used (" . $format . ")"; |
| 61 | throw new \InvalidArgumentException($message); |
| 62 | } |
| 63 | if (! ($quality >= 0 && $quality <= 100)) { |
| 64 | $message = "quality argument must be between 0 and 100 both inclusive. Used (" . $quality . ")"; |
| 65 | throw new \RangeException($message); |
| 66 | } |
| 67 | $this->quality = $quality; |
| 68 | $this->format = $format; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * (non-PHPdoc) |
| 73 | * |
| 74 | * @param Query $query |
| 75 | * The query to add the action to |
| 76 | * @return Query |
| 77 | * @see Action::perform() |
| 78 | */ |
| 79 | public function perform(Query $query): Query |
| 80 | { |
| 81 | $query->notWith('quality', Query::ARGUMENT_TYPE_INPUT); |
| 82 | |
| 83 | $query->setInputOption(" -quality " . $this->quality); |
| 84 | return $query; |
| 85 | } |
| 86 | } |