| Total Complexity | 8 |
| Total Lines | 81 |
| 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 | 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 |
|
| 89 | } |
||
| 90 | } |
||
| 91 |