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
Bordercolor
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 handling bordercolor 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 Bordercolor implements Action
32{
33    /**
34     * Color
35     *
36     * @var string
37     */
38    private string $color;
39
40    /**
41     * Construct new bordercolor action
42     *
43     * @param string $color Color
44     *
45     * @throws \InvalidArgumentException If the color supplied could not be parsed.
46     */
47    public function __construct(string $color)
48    {
49        if (Color::validHexColor($color) || Color::validRgbColor($color) || Color::validColorName($color)) {
50            $this->color = $color;
51        } else {
52            throw new \InvalidArgumentException('The color supplied could not be parsed');
53        }
54    }
55
56    /**
57     * (non-PHPdoc)
58     *
59     * @param Query $query The query to add the action to
60     *
61     * @see Action::perform()
62     */
63    public function perform(Query $query): Query
64    {
65        $query->notWith('bordercolor', \Karla\Query::ARGUMENT_TYPE_INPUT);
66        if (Color::validColorName($this->color)) {
67            $query->setInputOption(' -bordercolor ' . $this->color);
68        } else {
69            $query->setInputOption(' -bordercolor "' . $this->color . '"');
70        }
71        return $query;
72    }
73}