ScanResultFile   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureResultFile() 0 4 2
A getPath() 0 3 1
A __construct() 0 4 1
A getResult() 0 9 2
1
<?php
2
3
4
namespace cwreden\php7ccAnalyser;
5
6
7
final class ScanResultFile
8
{
9
    /**
10
     * @var string
11
     */
12
    private $path;
13
14
    /**
15
     * ScanResultFile constructor.
16
     * @param string $path
17
     * @throws ResultFileNotFoundException
18
     */
19 4
    public function __construct(string $path)
20
    {
21 4
        $this->ensureResultFile($path);
22 3
        $this->path = $path;
23 3
    }
24
25
    /**
26
     * @return string
27
     */
28 2
    public function getPath(): string
29
    {
30 2
        return $this->path;
31
    }
32
33
    /**
34
     * @return array
35
     * @throws ScanResultParsingException
36
     */
37 2
    public function getResult(): array
38
    {
39 2
        $content = file_get_contents($this->getPath());
40 2
        $json = json_decode($content, true);
41
42 2
        if (!is_array($json)) {
43 1
            throw new ScanResultParsingException($this->getPath());
44
        }
45 1
        return $json;
46
    }
47
48
    /**
49
     * @param string $path
50
     * @throws ResultFileNotFoundException
51
     */
52 4
    private function ensureResultFile(string $path): void
53
    {
54 4
        if (!file_exists($path)) {
55 1
            throw new ResultFileNotFoundException('php7cc result file not found.');
56
        }
57
    }
58
}