HTMLReporter::sortDefectsByNamespace()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace Solidifier\Reporters;
4
5
use PhpParser\PrettyPrinter\Standard;
6
7
class HTMLReporter
8
{
9
    private
10
        $content,
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $content.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
        $twig;
12
    
13
    public function __construct(\Twig_Environment $twig)
14
    {
15
        $this->content = null;
16
        $this->twig = $twig;    
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
17
    }
18
    
19
    public function render(array $defects)
20
    {
21
        $prettyPrint = new Standard();
22
        
23
        $this->content = $this->twig->render(
24
           'report.html.twig',
25
            array(
26
                'project' => 'Solidifier',
27
                'defects' => $this->sortDefectsByNamespace($defects),
28
                'printer' => $prettyPrint,
29
        ));
30
        
31
        return $this;
32
    }
33
    
34
    private function sortDefectsByNamespace(array $defects)
35
    {
36
        $result = array();
37
        ksort($defects);
38
        
39
        foreach($defects as $file => $fileDefects)
40
        {
41
            $namespace = implode('/', explode('/', $file, -1));
42
            
43
            if(! isset($result[$namespace]))
44
            {
45
                $result[$namespace] = array();
46
            }
47
            
48
            $result[$namespace][$file] = $fileDefects;
49
        }
50
        
51
        return $result;
52
    }
53
    
54
    public function save($reportFilename)
55
    {
56
        file_put_contents($reportFilename, $this->content);
57
    }
58
}