Total Complexity | 8 |
Total Lines | 82 |
Duplicated Lines | 0 % |
Coverage | 90% |
Changes | 0 |
1 | <?php |
||
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 |
|
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 |
|
90 | } |
||
91 | } |
||
92 |