Completed
Push — output_parsers_refactor ( 710907...9ffc6c )
by Alessandro
02:42
created

JSONLogFetcher::fetch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2.032
1
<?php
2
3
namespace Paraunit\Parser;
4
5
use Paraunit\Configuration\JSONLogFilename;
6
use Paraunit\Exception\JSONLogNotFoundException;
7
use Paraunit\Process\ParaunitProcessInterface;
8
9
/**
10
 * Class JSONLogFetcher
11
 * @package Paraunit\Parser
12
 */
13
class JSONLogFetcher
14
{
15
    /** @var  JSONLogFilename */
16
    private $fileName;
17
18
    /**
19
     * JSONLogFetcher constructor.
20
     * @param JSONLogFilename $fileName
21
     */
22 1
    public function __construct(JSONLogFilename $fileName)
23
    {
24 1
        $this->fileName = $fileName;
25 1
    }
26
27
    /**
28
     * @param ParaunitProcessInterface $process
29
     * @return string The full JSON log
30
     * @throws JSONLogNotFoundException
31
     */
32 1
    public function fetch(ParaunitProcessInterface $process)
33
    {
34 1
        $filePath = $this->fileName->generate($process);
35
36 1
        if ( ! file_exists($filePath)) {
37 1
            throw new JSONLogNotFoundException($process);
38
        }
39
40
        return file_get_contents($filePath);
41
    }
42
}
43