Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Background
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
6
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
4
 perform
100.00% covered (success)
100.00%
5 / 5
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;
21use Karla\Color;
22
23/**
24 * Class for handeling background 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 Background implements Action
32{
33    /**
34     * Color
35     *
36     * @var string
37     */
38    private string $color;
39
40    /**
41     * Construct new background action
42     *
43     * @param string $color
44     *            Color
45     *
46     * @throws \InvalidArgumentException If the color supplied could not be parsed.
47     */
48    public function __construct(string $color)
49    {
50        if (Color::validHexColor($color) || Color::validRgbColor($color) || Color::validColorName($color)) {
51            $this->color = $color;
52        } else {
53            throw new \InvalidArgumentException('The color supplied could not be parsed.');
54        }
55    }
56
57    /**
58     * (non-PHPdoc)
59     *
60     * @param Query $query
61     *            The query to add the action to
62     * @return Query
63     * @see Action::perform()
64     */
65    public function perform(Query $query): Query
66    {
67        $query->notWith('background', Query::ARGUMENT_TYPE_INPUT);
68        if (Color::validColorName($this->color)) {
69            $query->setInputOption(' -background ' . $this->color);
70        } else {
71            $query->setInputOption(' -background "' . $this->color . '"');
72        }
73        return $query;
74    }
75}