Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Profile
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
11
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
7
 perform
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
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;
21
22/**
23 * Class for handling profile action
24 *
25 * @category Utility
26 * @author   Johannes Skov Frandsen <jsf@greenoak.dk>
27 * @license  http://www.opensource.org/licenses/mit-license.php MIT
28 * @link     https://github.com/localgod/karla Karla
29 */
30class Profile implements Action
31{
32    /**
33     * Profile path
34     *
35     * @var string
36     */
37    private string $profilePath;
38
39    /**
40     * Profile name
41     *
42     * @var string
43     */
44    private string $profileName;
45
46    /**
47     * Remove profile
48     *
49     * @var bool
50     */
51    private bool $remove;
52
53    /**
54     * Construct a new profile action
55     *
56     * @param string $profilePath Profile path
57     * @param string $profileName Profile name
58     * @param bool $remove Should the profile be removed? (default is false)
59     *
60     * @throws \LogicException profilePath or profileName must be set, but not both.
61     * @throws \InvalidArgumentException If profile input file (' . $profilePath . ') could not be found.
62     */
63    public function __construct(string $profilePath = "", string $profileName = "", $remove = false)
64    {
65        if (($profilePath == '' && $profileName == '') || ($profilePath != '' && $profileName != '')) {
66            $message = 'profilePath or profileName must be set, but not both.';
67            throw new \LogicException($message);
68        }
69        if ($profilePath != '' && ! file_exists($profilePath)) {
70            $message = 'Profile input file (' . $profilePath . ') could not be found';
71            throw new \InvalidArgumentException($message);
72        }
73
74        $this->profilePath = $profilePath;
75        $this->profileName = $profileName;
76        $this->remove = $remove;
77    }
78
79    /**
80     * (non-PHPdoc)
81     *
82     * @param Query $query The query to add the action to
83     *
84     * @see Action::perform()
85     */
86    public function perform(Query $query): Query
87    {
88        if ($this->profilePath != '') {
89            $query->setOutputOption(' ' . ($this->remove ? '+' : '-') . 'profile "' . $this->profilePath . '" ');
90        } else {
91            $query->setOutputOption(' ' . ($this->remove ? '+' : '-') . 'profile ' . $this->profileName);
92        }
93
94        return $query;
95    }
96}