Completed
Push — master ( aae6d4...77a0b7 )
by Derek Stephen
02:32
created

WebPStrategy::getFileExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Del\Image\Strategy;
4
5
class WebPStrategy extends TransparentStrategy implements ImageTypeStrategyInterface
6
{
7
    /**
8
     * @param string $filename
9
     * @return resource
10
     */
11 2
    public function create(string $filename)
12
    {
13 2
        return \imagecreatefromwebp($filename);
0 ignored issues
show
Bug Best Practice introduced by
The expression return imagecreatefromwebp($filename) could also return false which is incompatible with the documented return type resource. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
14
    }
15
16
    /**
17
     * @param resource $resource
18
     * @param string $filename
19
     * @param int $compression
20
     * @return void
21
     */
22 2
    public function save($resource, string $filename = null, int $compression = 100): void
23
    {
24 2
        \imagewebp($resource, $filename, $compression);
25 2
    }
26
27
    /**
28
     * @return string
29
     */
30 1
    public function getContentType(): string
31
    {
32 1
        return 'image/webp';
33
    }
34
35
    /**
36
     * @param $resource
37
     */
38 2
    public function render($resource): void
39
    {
40 2
        imagealphablending($resource, true);
41 2
        imagesavealpha($resource, true);
42 2
        imagewebp($resource);
43 2
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getFileExtension(): string
49
    {
50
        return 'webp';
51
    }
52
}