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

PngStrategy::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 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
}