Total Complexity | 7 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Coverage | 87.5% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class LocalImage implements Image |
||
11 | { |
||
12 | private string $path; |
||
13 | private string $filename; |
||
14 | |||
15 | public function __construct(string $path, ?string $filename = null) |
||
16 | 4 | { |
|
17 | if (!file_exists($path)) { |
||
18 | 4 | throw new LogicException(sprintf('Image %s does not exist.', $path)); |
|
19 | 1 | } |
|
20 | |||
21 | if (exif_imagetype($path) !== IMAGETYPE_PNG) { |
||
22 | 3 | throw new LogicException('Image should be of type PNG.'); |
|
23 | 3 | } |
|
24 | 1 | ||
25 | $this->path = $path; |
||
26 | $this->filename = $filename ?? basename($path); |
||
27 | } |
||
28 | 2 | ||
29 | 2 | public function setFilename(string $filename): void |
|
30 | 2 | { |
|
31 | $this->filename = $filename; |
||
32 | 1 | } |
|
33 | |||
34 | 1 | public function getContents(): string |
|
35 | 1 | { |
|
36 | return (string) file_get_contents($this->path); |
||
37 | } |
||
38 | |||
39 | public function getPath(): string |
||
40 | { |
||
41 | return $this->path; |
||
42 | 2 | } |
|
43 | |||
44 | 2 | public function getFilename(): string |
|
47 | 2 | } |
|
48 | } |
||
49 |