Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Profile | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
56 | |||
| perform | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
| 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 | |
| 15 | declare(strict_types=1); |
| 16 | |
| 17 | namespace Karla\Action; |
| 18 | |
| 19 | use Karla\Query; |
| 20 | use Karla\Action; |
| 21 | |
| 22 | /** |
| 23 | * Class for handeling 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 | */ |
| 30 | class 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 boolean |
| 50 | */ |
| 51 | private bool $remove; |
| 52 | |
| 53 | /** |
| 54 | * Construct a new profile action |
| 55 | * |
| 56 | * @param string $profilePath |
| 57 | * Profile path |
| 58 | * @param string $profileName |
| 59 | * Profile name |
| 60 | * @param boolean $remove |
| 61 | * Should the profile be removed? (default is false) |
| 62 | * |
| 63 | * @throws \LogicException profilePath or profileName must be set, but not both. |
| 64 | * @throws \InvalidArgumentException If profile input file (' . $profilePath . ') could not be found. |
| 65 | */ |
| 66 | public function __construct(string $profilePath = "", string $profileName = "", $remove = false) |
| 67 | { |
| 68 | if (($profilePath == '' && $profileName == '') || ($profilePath != '' && $profileName != '')) { |
| 69 | $message = 'profilePath or profileName must be set, but not both.'; |
| 70 | throw new \LogicException($message); |
| 71 | } |
| 72 | if ($profilePath != '' && ! file_exists($profilePath)) { |
| 73 | $message = 'Profile input file (' . $profilePath . ') could not be found'; |
| 74 | throw new \InvalidArgumentException($message); |
| 75 | } |
| 76 | |
| 77 | $this->profilePath = $profilePath; |
| 78 | $this->profileName = $profileName; |
| 79 | $this->remove = $remove; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * (non-PHPdoc) |
| 84 | * |
| 85 | * @param Query $query |
| 86 | * The query to add the action to |
| 87 | * @return Query |
| 88 | * @see Action::perform() |
| 89 | */ |
| 90 | public function perform(Query $query): Query |
| 91 | { |
| 92 | if ($this->profilePath != '') { |
| 93 | $query->setOutputOption(' ' . ($this->remove ? '+' : '-') . 'profile "' . $this->profilePath . '" '); |
| 94 | } else { |
| 95 | $query->setOutputOption(' ' . ($this->remove ? '+' : '-') . 'profile ' . $this->profileName); |
| 96 | } |
| 97 | |
| 98 | return $query; |
| 99 | } |
| 100 | } |