Test Failed
Pull Request — main (#22)
by Jeremy
12:54
created

QualityFilter::apply()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 16
rs 9.6111
cc 5
nc 5
nop 1
1
<?php
2
3
namespace Conlect\ImageIIIF\Filters;
4
5
use Intervention\Image\Interfaces\ImageInterface;
6
use Intervention\Image\Interfaces\ModifierInterface;
7
8
class QualityFilter implements ModifierInterface
9
{
10
    private $quality;
11
12
    /**
13
     * Creates new instance of filter
14
     *
15
     */
16
    public function __construct($quality)
17
    {
18
        $this->quality = $quality;
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
        if ($this->quality === 'default') {
31
            return $image;
32
        }
33
34
        if ($this->quality === 'gray') {
35
            return $image->greyscale();
36
        }
37
38
        if ($this->quality === 'color') {
39
            return $image;
40
        }
41
42
        if ($this->quality === 'bitonal') {
43
            return $image;
44
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 42 is false. This is incompatible with the type-hinted return Intervention\Image\Interfaces\ImageInterface. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
45
    }
46
}
47