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

PngStrategy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
c 0
b 0
f 0
dl 0
loc 47
ccs 13
cts 15
cp 0.8667
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 4 1
A create() 0 3 1
A getContentType() 0 3 1
A render() 0 5 1
A getFileExtension() 0 3 1
1
<?php
2
3
namespace Del\Image\Strategy;
4
5
class PngStrategy extends TransparentStrategy implements ImageTypeStrategyInterface
6
{
7
    /**
8
     * @param string $filename
9
     * @return resource
10
     */
11 12
    public function create(string $filename)
12
    {
13 12
        return \imagecreatefrompng($filename);
0 ignored issues
show
Bug Best Practice introduced by
The expression return imagecreatefrompng($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 1
    public function save($resource, string $filename = null, int $compression = 100): void
23
    {
24 1
        unset($compression);
25 1
        \imagepng($resource, $filename);
26 1
    }
27
28
    /**
29
     * @return string
30
     */
31 2
    public function getContentType(): string
32
    {
33 2
        return 'image/png';
34
    }
35
36
    /**
37
     * @param $resource
38
     */
39 8
    public function render($resource): void
40
    {
41 8
        imagealphablending($resource, true);
42 8
        imagesavealpha($resource, true);
43 8
        imagepng($resource);
44 8
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getFileExtension(): string
50
    {
51
        return 'png';
52
    }
53
}