Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Density
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 perform
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 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
15declare(strict_types=1);
16
17namespace Karla\Action;
18
19use Karla\Query;
20use Karla\Action;
21
22/**
23 * Class for handling density 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 Density implements Action
31{
32    /**
33     * Width
34     *
35     * @var int
36     */
37    private int $width;
38
39    /**
40     * Height
41     *
42     * @var int
43     */
44    private int $height;
45
46    /**
47     * Is it an output argument
48     *
49     * @var bool
50     */
51    private bool $output;
52
53    /**
54     * Set the density of the output image.
55     *
56     * @param int $width The width of the image
57     * @param int $height The height of the image
58     * @param bool $output If true, density is set for the resulting image;
59     *                     if false, density is used for reading the input image
60     *
61     * @throws \InvalidArgumentException
62     */
63    public function __construct(int $width, int $height, bool $output)
64    {
65        $this->width = $width;
66        $this->height = $height;
67        $this->output = $output;
68    }
69
70    /**
71     * (non-PHPdoc)
72     *
73     * @param Query $query The query to add the action to
74     *
75     * @see Action::perform()
76     * @throws \BadMethodCallException if density has already been called
77     */
78    public function perform(Query $query): Query
79    {
80        $query->notWith('density', Query::ARGUMENT_TYPE_INPUT);
81        $query->notWith('density', Query::ARGUMENT_TYPE_OUTPUT);
82
83        if ($this->output) {
84            $query->setOutputOption(" -density " . $this->width . "x" . $this->height);
85        } else {
86            $query->setInputOption(" -density " . $this->width . "x" . $this->height);
87        }
88        return $query;
89    }
90}