Crop   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 3
1
<?php
2
3
namespace yiicod\easyimage\tools;
4
5
use Exception;
6
use Imagine\Image\Box;
7
use Imagine\Image\ManipulatorInterface;
8
use Imagine\Image\Point;
9
use yiicod\easyimage\base\ToolInterface;
10
11
/**
12
 * Class Crop
13
 * Crop tool
14
 *
15
 * @author Virchenko Maksim <[email protected]>
16
 *
17
 * @package yiicod\easyimage\tools
18
 */
19
class Crop 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 "Crop"');
35
        }
36
37
        return $image->crop(new Point(
38
            $params['offset_x'] ?? 0,
39
            $params['offset_y'] ?? 0
40
        ), new Box($params['width'], $params['height']));
41
    }
42
}
43