Completed
Pull Request — master (#235)
by Kévin
03:13
created

JsonFormatter::reportEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PHPSA\Report\Formatter;
4
5
use PHPSA\Issue;
6
7
class JsonFormatter implements ReportFormatter
8
{
9
    protected $isFirstIssue = true;
10
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function reportBeginning()
15
    {
16
        $this->isFirstIssue = true;
17
        return '[';
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function reportEnd()
24
    {
25
        return ']';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function formatIssue(Issue $issue)
32
    {
33
        $json = json_encode($issue->toArray());
34
35
        if (!$this->isFirstIssue) {
36
            $json = ', '.$json;
37
        }
38
39
        $this->isFirstIssue = false;
40
41
        return $json;
42
    }
43
}
44