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 handeling 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
46     *            The program to use
47     * @param string $gravity
48     *            Gravity
49     *
50     * @throws \InvalidArgumentException If the supplied gravity is not supported by imagemagick.
51     */
52    public function __construct(Program $program, string $gravity)
53    {
54        if (! Support::gravity($program, $gravity)) {
55            $message = 'The supplied gravity (' . $gravity . ') is not supported by imagemagick';
56            throw new \InvalidArgumentException($message);
57        }
58        $this->gravity = $gravity;
59    }
60
61    /**
62     * (non-PHPdoc)
63     *
64     * @param Query $query
65     *            The query to add the action to
66     * @return Query
67     * @see Action::perform()
68     */
69    public function perform(Query $query): Query
70    {
71        $query->notWith('gravity', Query::ARGUMENT_TYPE_INPUT);
72        $query->setInputOption(" -gravity " . $this->gravity);
73        return $query;
74    }
75}