Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Quality
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
 perform
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
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
15declare(strict_types=1);
16
17namespace Karla\Action;
18
19use Karla\Query;
20use Karla\Action;
21
22/**
23 * Class for handling 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 */
30class Quality implements Action
31{
32    /**
33     * The quality to use
34     *
35     * @var int
36     */
37    private int $quality;
38
39    /**
40     * Construct a new quality action
41     *
42     * @param int $quality Quality
43     * @param string $format Format
44     *
45     * @throws \InvalidArgumentException
46     * @throws \RangeException
47     */
48    public function __construct(int $quality, string $format)
49    {
50        if (! preg_match('/^jpeg|jpg|png$/', $format)) {
51            $message = "'quality()' is only supported for the jpeg and png format. Used (" . $format . ")";
52            throw new \InvalidArgumentException($message);
53        }
54        if (! ($quality >= 0 && $quality <= 100)) {
55            $message = "quality argument must be between 0 and 100 both inclusive. Used (" . $quality . ")";
56            throw new \RangeException($message);
57        }
58        $this->quality = $quality;
59    }
60
61    /**
62     * (non-PHPdoc)
63     *
64     * @param Query $query The query to add the action to
65     *
66     * @see Action::perform()
67     */
68    public function perform(Query $query): Query
69    {
70        $query->notWith('quality', Query::ARGUMENT_TYPE_INPUT);
71
72        $query->setInputOption(" -quality " . $this->quality);
73        return $query;
74    }
75}