LocalImage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 37
ccs 14
cts 16
cp 0.875
rs 10
c 1
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilename() 0 3 1
A __construct() 0 12 3
A getContents() 0 3 1
A getPath() 0 3 1
A setFilename() 0 3 1
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