Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Type
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 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\Support;
21use Karla\Action;
22
23/**
24 * Class for handeling type action
25 *
26 * @category Utility
27 * @author   Johannes Skov Frandsen <jsf@greenoak.dk>
28 * @license  http://www.opensource.org/licenses/mit-license.php MIT
29 * @link     https://github.com/localgod/karla Karla
30 */
31class Type implements Action
32{
33    /**
34     * The type to use
35     *
36     * @var string
37     */
38    private string $type;
39
40    /**
41     * Create a new type action
42     *
43     * @param \Karla\Program $program
44     *            The program to use
45     * @param string $type
46     *            The type to use
47     *
48     * @throws \InvalidArgumentException If the supplied colorspace is not supported by imagemagick
49     */
50    public function __construct($program, $type)
51    {
52        if (! Support::imageTypes($program, $type)) {
53            $message = 'The supplied colorspace (' . $type . ') is not supported by imagemagick';
54            throw new \InvalidArgumentException($message);
55        }
56        $this->type = $type;
57    }
58
59    /**
60     * (non-PHPdoc)
61     *
62     * @param Query $query
63     *            The query to add the action to
64     * @return Query
65     * @see Action::perform()
66     */
67    public function perform(Query $query): Query
68    {
69        $query->notWith('type', Query::ARGUMENT_TYPE_OUTPUT);
70
71        $query->setOutputOption(" -type " . $this->type . ' ');
72        return $query;
73    }
74}