Flip::handle()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.2
cc 4
eloc 13
nc 4
nop 2
1
<?php
2
3
namespace yiicod\easyimage\tools;
4
5
use Exception;
6
use Imagine\Image\ManipulatorInterface;
7
use yiicod\easyimage\base\ToolInterface;
8
9
/**
10
 * Class Flip
11
 * Flip image tool
12
 *
13
 * @author Virchenko Maksim <[email protected]>
14
 *
15
 * @package yiicod\easyimage\tools
16
 */
17
class Flip implements ToolInterface
18
{
19
    /**
20
     * Handle image
21
     *
22
     * @param ManipulatorInterface $image
23
     * @param array $params
24
     *
25
     * @return ManipulatorInterface
26
     *
27
     * @throws Exception
28
     */
29
    public static function handle(ManipulatorInterface $image, array $params = []): ManipulatorInterface
30
    {
31
        if (false === isset($params['axis'])) {
32
            throw new Exception('Param "axis" is required for action "Flip"');
33
        }
34
35
        switch ($params['axis']) {
36
            case 'horizontal':
37
                return $image->flipHorizontally();
38
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
39
            case 'vertical':
40
                return $image->flipVertically();
41
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
42
            default:
43
                throw new Exception('Param "axis" must be equal "horizontal" or "vertical" for action "Rotate"');
44
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
45
        }
46
    }
47
}
48