JsonReporter::getOutput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace PHPSemVerCheckerGit\Reporter;
4
5
use PHPSemVerChecker\Report\Report;
6
use PHPSemVerChecker\Wrapper\Filesystem;
7
use PHPSemVerChecker\Reporter\JsonReporter as BaseJsonReporter;
8
9
class JsonReporter
10
{
11
	/**
12
	 * @var \PHPSemVerChecker\Report\Report
13
	 */
14
	protected $report;
15
	/**
16
	 * @var string
17
	 */
18
	protected $path;
19
	/**
20
	 * @var \PHPSemVerChecker\Wrapper\Filesystem
21
	 */
22
	protected $filesystem;
23
	/**
24
	 * @var \PHPSemVerChecker\Reporter\JsonReporter
25
	 */
26
	protected $baseJsonReporter;
27
	private $beforeHash;
28
	private $afterHash;
29
30
	/**
31
	 * @param \PHPSemVerChecker\Report\Report      $report
32
	 * @param string                               $path
33
	 * @param string                               $beforeHash
34
	 * @param string                               $afterHash
35
	 * @param \PHPSemVerChecker\Wrapper\Filesystem $filesystem
36
	 */
37
	public function __construct(Report $report, $path, $beforeHash, $afterHash, Filesystem $filesystem = null)
38
	{
39
		$this->report = $report;
40
		$this->path = $path;
41
		$this->beforeHash = $beforeHash;
42
		$this->afterHash = $afterHash;
43
		$this->filesystem = $filesystem ?: new Filesystem();
44
		$this->baseJsonReporter = new BaseJsonReporter($report, $path);
45
	}
46
47
	/**
48
	 * @return array
49
	 */
50
	public function getOutput()
51
	{
52
		$output = [];
53
		$output['before'] = $this->beforeHash;
54
		$output['after'] = $this->afterHash;
55
		$output['delta'] = $this->baseJsonReporter->getOutput();
56
57
		return $output;
58
	}
59
60
	public function output()
61
	{
62
		$this->filesystem->write($this->path, json_encode($this->getOutput(), JSON_PRETTY_PRINT));
63
	}
64
}
65