LocalImage::getFilename()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\ApplePassbook\MetaData\Image;
6
7
use LauLamanApps\ApplePassbook\MetaData\Image;
8
use LogicException;
9
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
45
    {
46
        return $this->filename;
47 2
    }
48
}
49