Passed
Push — develop ( 0112d6...38c008 )
by Daniel
05:14
created

ImageMetadata   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 81
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getImagineKey() 0 3 1
A getHeight() 0 3 1
A getPublicPath() 0 3 1
A __construct() 0 18 3
A getFilePath() 0 3 1
A getWidth() 0 3 1
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Serializer;
4
5
use Silverback\ApiComponentBundle\Exception\FileMissingException;
6
use Silverback\ApiComponentBundle\Exception\FileNotImageException;
7
8
class ImageMetadata
9
{
10
    /**
11
     * @var int
12
     */
13
    private $width;
14
    /**
15
     * @var int
16
     */
17
    private $height;
18
    /**
19
     * @var string
20
     */
21
    private $filePath;
22
    /**
23
     * @var string
24
     */
25
    private $publicPath;
26
    /**
27
     * @var string|null
28
     */
29
    private $imagineKey;
30
31 1
    public function __construct(
32
        string $filePath,
33
        string $publicPath,
34
        ?string $imagineKey = null
35
    ) {
36 1
        $this->filePath = $filePath;
37 1
        $this->publicPath = $publicPath;
38
39 1
        if (!file_exists($filePath)) {
40
            throw new FileMissingException(sprintf('The file %s does not exist while constructing %s', $filePath, self::class));
41
        }
42
43 1
        if (false === \exif_imagetype($filePath)) {
44
            throw new FileNotImageException(sprintf('The file %s is not an image while constructing %s', $filePath, self::class));
45
        }
46
47 1
        [$this->width, $this->height] = getimagesize($filePath);
48 1
        $this->imagineKey= $imagineKey;
49 1
    }
50
51
    /**
52
     * @return int
53
     */
54 1
    public function getWidth(): int
55
    {
56 1
        return $this->width;
57
    }
58
59
    /**
60
     * @return int
61
     */
62 1
    public function getHeight(): int
63
    {
64 1
        return $this->height;
65
    }
66
67
    /**
68
     * @return string
69
     */
70 1
    public function getFilePath(): string
71
    {
72 1
        return $this->filePath;
73
    }
74
75
    /**
76
     * @return string
77
     */
78 1
    public function getPublicPath(): string
79
    {
80 1
        return $this->publicPath;
81
    }
82
83
    /**
84
     * @return null|string
85
     */
86 1
    public function getImagineKey(): ?string
87
    {
88 1
        return $this->imagineKey;
89
    }
90
}
91