FilePersistenceAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
}