FilePersistenceAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A persist() 0 4 1
A __construct() 0 3 1
A getLast() 0 7 2
1
<?php
2
3
namespace cwreden\php7ccAnalyser;
4
5
6
class FilePersistenceAdapter implements PersistenceAdapterInterface
7
{
8
    private $path;
9
10 2
    public function __construct($path)
11
    {
12 2
        $this->path = $path;
13 2
    }
14
15
    /**
16
     * @param Scan $scan
17
     */
18 1
    public function persist(Scan $scan): void
19
    {
20 1
        $serializedScan = serialize($scan);
21 1
        file_put_contents($this->path, $serializedScan);
22 1
    }
23
24
    /**
25
     * @return Scan
26
     * @throws NoPreviousScanFoundException
27
     */
28 2
    public function getLast(): Scan
29
    {
30 2
        if (!file_exists($this->path)) {
31 1
            throw new NoPreviousScanFoundException();
32
        }
33 1
        $content = file_get_contents($this->path);
34 1
        return unserialize($content);
35
    }
36
}