FilePersistenceAdapter::getLast()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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
}