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

ImageMetadata::getWidth()   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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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