Resize::handle()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.2
cc 4
eloc 6
nc 2
nop 2
1
<?php
2
3
namespace yiicod\easyimage\tools;
4
5
use Exception;
6
use Imagine\Image\Box;
7
use Imagine\Image\ImageInterface;
8
use Imagine\Image\ManipulatorInterface;
9
use yiicod\easyimage\base\ToolInterface;
10
11
/**
12
 * Class Resize
13
 * Resize image tool
14
 *
15
 * @author Virchenko Maksim <[email protected]>
16
 *
17
 * @package yiicod\easyimage\tools
18
 */
19
class Resize implements ToolInterface
20
{
21
    /**
22
     * Handle image
23
     *
24
     * @param ManipulatorInterface $image
25
     * @param array $params
26
     *
27
     * @return ManipulatorInterface
28
     *
29
     * @throws Exception
30
     */
31
    public static function handle(ManipulatorInterface $image, array $params = []): ManipulatorInterface
32
    {
33
        if (false === isset($params['width']) || false === isset($params['height'])) {
34
            throw new Exception('Params "width" and "height" is required for action "Resize"');
35
        }
36
37
        return $image->resize(
38
            new Box($params['width'], $params['height']),
39
            isset($params['filter']) ? $params['filter'] : ImageInterface::FILTER_UNDEFINED
40
        );
41
    }
42
}
43