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

JpegStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 6
eloc 7
c 0
b 0
f 0
dl 0
loc 53
ccs 12
cts 14
cp 0.8571
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A save() 0 3 1
A render() 0 3 1
A handleTransparency() 0 4 1
A getContentType() 0 3 1
A getFileExtension() 0 3 1
1
<?php
2
3
namespace Del\Image\Strategy;
4
5
class JpegStrategy implements ImageTypeStrategyInterface
6
{
7
    /**
8
     * @param string $filename
9
     * @return null|resource
10
     */
11 6
    public function create(string $filename)
12
    {
13 6
        return \imagecreatefromjpeg($filename);
0 ignored issues
show
Bug Best Practice introduced by
The expression return imagecreatefromjpeg($filename) could also return false which is incompatible with the documented return type null|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
     */
21 1
    public function save($resource, string $filename = null, int $compression = 100): void
22
    {
23 1
        \imagejpeg($resource, $filename, $compression);
24 1
    }
25
26
    /**
27
     * @return string
28
     */
29 1
    public function getContentType(): string
30
    {
31 1
        return 'image/jpeg';
32
    }
33
34
    /**
35
     * @param resource $resource
36
     */
37 4
    public function render($resource): void
38
    {
39 4
        \imagejpeg($resource);
40 4
    }
41
42
    /**
43
     * @param resource $newImage
44
     * @param resource $image
45
     */
46 1
    public function handleTransparency($newImage, $image): void
47
    {
48
        // Jpeg's aren't transparent.
49 1
        return;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getFileExtension(): string
56
    {
57
        return 'jpg';
58
    }
59
}