Passed
Push — master ( 05757a...dfbf27 )
by Derek Stephen
09:55
created

PngStrategy::getFileExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 10
    public function create(string $filename)
12
    {
13 10
        return \imagecreatefrompng($filename);
0 ignored issues
show
Bug Best Practice introduced by
The expression return imagecreatefrompng($filename) also could return the type GdImage which is incompatible with the documented return type resource.
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, int $compression = 100): void
23
    {
24 1
        unset($compression);
25 1
        \imagepng($resource, $filename);
26 1
    }
27
28
    /**
29
     * @return string
30
     */
31 1
    public function getContentType(): string
32
    {
33 1
        return 'image/png';
34
    }
35
36
    /**
37
     * @param $resource
38
     */
39 7
    public function render($resource): void
40
    {
41 7
        imagealphablending($resource, true);
42 7
        imagesavealpha($resource, true);
43 7
        imagepng($resource);
44
    }
45
}