Passed
Pull Request — main (#22)
by
unknown
04:18 queued 02:08
created

RotationFilter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A apply() 0 11 4
1
<?php
2
3
namespace Conlect\ImageIIIF\Filters;
4
5
use Intervention\Image\Interfaces\ImageInterface;
6
use Intervention\Image\Interfaces\ModifierInterface;
7
8
class RotationFilter implements ModifierInterface
9
{
10
    private $rotation;
11
12
    /**
13
     * Creates new instance of filter
14
     *
15
     */
16
    public function __construct($rotation)
17
    {
18
        $this->rotation = $rotation;
19
    }
20
21
    /**
22
     * Applies filter effects to given image
23
     *
24
     * @param  ImageInterface $image
25
     *
26
     * @return  ImageInterface
27
     */
28
    public function apply(ImageInterface $image): ImageInterface
29
    {
30
        // transparent background if possible
31
32
        $mirror = strpos($this->rotation, '!') === false ? false : true;
33
        $rotation = $mirror ? substr($this->rotation, 1) : $this->rotation;
34
        if ($mirror) {
35
            $image->flop();
36
        }
37
38
        return $image->rotate(-$rotation);
39
    }
40
}
41