Completed
Pull Request — master (#235)
by Kévin
04:23 queued 01:09
created

JsonFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reportBeginning() 0 5 1
A reportEnd() 0 4 1
A formatIssue() 0 12 2
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