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
Gravity
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\Program;
20use Karla\Query;
21use Karla\Action;
22use Karla\Support;
23use Karla\Karla;
24
25/**
26 * Class for handling gravity action
27 *
28 * @category Utility
29 * @author   Johannes Skov Frandsen <jsf@greenoak.dk>
30 * @license  http://www.opensource.org/licenses/mit-license.php MIT
31 * @link     https://github.com/localgod/karla Karla
32 */
33class Gravity implements Action
34{
35    /**
36     * The gravity of the image
37     *
38     * @var string
39     */
40    private string $gravity;
41
42    /**
43     * Construct a new gravity action
44     *
45     * @param \Karla\Program $program The program to use
46     * @param string $gravity Gravity
47     *
48     * @throws \InvalidArgumentException If the supplied gravity is not supported by imagemagick.
49     */
50    public function __construct(Program $program, string $gravity)
51    {
52        if (! Support::gravity($program, $gravity)) {
53            $message = 'The supplied gravity (' . $gravity . ') is not supported by imagemagick';
54            throw new \InvalidArgumentException($message);
55        }
56        $this->gravity = $gravity;
57    }
58
59    /**
60     * (non-PHPdoc)
61     *
62     * @param Query $query The query to add the action to
63     *
64     * @see Action::perform()
65     */
66    public function perform(Query $query): Query
67    {
68        $query->notWith('gravity', Query::ARGUMENT_TYPE_INPUT);
69        $query->setInputOption(" -gravity " . $this->gravity);
70        return $query;
71    }
72}