WebPStrategy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
c 0
b 0
f 0
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A save() 0 3 1
A render() 0 5 1
A getContentType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Del\Image\Strategy;
6
7
use GdImage;
8
9
class WebPStrategy extends TransparentStrategy implements ImageTypeStrategyInterface
10
{
11 2
    public function create(string $filename): GdImage
12
    {
13 2
        return \imagecreatefromwebp($filename);
0 ignored issues
show
Bug Best Practice introduced by
The expression return imagecreatefromwebp($filename) could return the type resource which is incompatible with the type-hinted return GdImage. Consider adding an additional type-check to rule them out.
Loading history...
14
    }
15
16 1
    public function save(GdImage $resource, string $filename, int $compression = 100): void
17
    {
18 1
        \imagewebp($resource, $filename);
19
    }
20
21 1
    public function getContentType(): string
22
    {
23 1
        return 'image/webp';
24
    }
25
26 2
    public function render(GdImage $resource): void
27
    {
28 2
        \imagealphablending($resource, true);
29 2
        \imagesavealpha($resource, true);
30 2
        \imagewebp($resource);
31
    }
32
}
33