Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Sepia | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| perform | |
100.00% |
3 / 3 |
|
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 | |
| 15 | declare(strict_types=1); |
| 16 | |
| 17 | namespace Karla\Action; |
| 18 | |
| 19 | use Karla\Query; |
| 20 | use Karla\Action; |
| 21 | |
| 22 | /** |
| 23 | * Class for handling sepia 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 Sepia implements Action |
| 31 | { |
| 32 | /** |
| 33 | * Threshold |
| 34 | * |
| 35 | * @var int |
| 36 | */ |
| 37 | private int $threshold; |
| 38 | |
| 39 | /** |
| 40 | * Construct a new size action |
| 41 | * |
| 42 | * @param int $threshold Threshold |
| 43 | * |
| 44 | * @throws \InvalidArgumentException If The supplied threshold is not between 0 and 100 |
| 45 | */ |
| 46 | public function __construct(int $threshold) |
| 47 | { |
| 48 | if ($threshold > 100 || $threshold < 0) { |
| 49 | $message = 'The supplied threshold (' . $threshold . ') must be between 0 and 100'; |
| 50 | throw new \InvalidArgumentException($message); |
| 51 | } |
| 52 | $this->threshold = (int) $threshold; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * (non-PHPdoc) |
| 57 | * |
| 58 | * @param Query $query The query to add the action to |
| 59 | * |
| 60 | * @see Action::perform() |
| 61 | */ |
| 62 | public function perform(Query $query): Query |
| 63 | { |
| 64 | $query->notWith('sepia-tone', Query::ARGUMENT_TYPE_OUTPUT); |
| 65 | $query->setOutputOption(" -sepia-tone " . $this->threshold . '% '); |
| 66 | |
| 67 | return $query; |
| 68 | } |
| 69 | } |