Passed
Push — develop ( a2aeae...9ee07e )
by Daniel
05:41
created

ImageMetadata::getHeight()   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
    {
37 1
        $this->filePath = $filePath;
38 1
        $this->publicPath = $publicPath;
39
40 1
        if (!file_exists($filePath)) {
41
            throw new FileMissingException(sprintf('The file %s does not exist while constructing %s', $filePath, self::class));
42
        }
43
44 1
        if (false === \exif_imagetype($filePath)) {
45
            throw new FileNotImageException(sprintf('The file %s is not an image while constructing %s', $filePath, self::class));
46
        }
47
48 1
        [$this->width, $this->height] = getimagesize($filePath);
49 1
        $this->imagineKey= $imagineKey;
50 1
    }
51
52
    /**
53
     * @return int
54
     */
55 1
    public function getWidth(): int
56
    {
57 1
        return $this->width;
58
    }
59
60
    /**
61
     * @return int
62
     */
63 1
    public function getHeight(): int
64
    {
65 1
        return $this->height;
66
    }
67
68
    /**
69
     * @return string
70
     */
71 1
    public function getFilePath(): string
72
    {
73 1
        return $this->filePath;
74
    }
75
76
    /**
77
     * @return string
78
     */
79 1
    public function getPublicPath(): string
80
    {
81 1
        return $this->publicPath;
82
    }
83
84
    /**
85
     * @return null|string
86
     */
87 1
    public function getImagineKey(): ?string
88
    {
89 1
        return $this->imagineKey;
90
    }
91
}
92