Completed
Push — master ( 86b2cd...b16d12 )
by Richard
03:26
created

DiffPerRuleReport   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A default_template() 0 3 1
B generate() 0 30 1
1
<?php
2
3
namespace Lechimp\Dicto\Report;
4
5
/**
6
 * Shows the diff in violations between two commits per rule.
7
 */
8
class DiffPerRuleReport extends Report {
9
    /**
10
     * @inheritdoc
11
     */
12
    protected function default_template() {
13
        return __DIR__."/../../templates/diff_per_rule.php";
14
    }
15
16
    /**
17
     * @inheritdoc
18
     */
19
    public function generate() {
20
        $cur_run = $this->queries->current_run();
21
        $prev_run = $this->queries->previous_run_with_different_commit();
22
        return
23
            [ "run_id"  => $cur_run
24
            , "current" => $this->queries->run_info($cur_run)
25
            , "previous" => $this->queries->run_info($prev_run)
26
            , "violations" =>
27
                [ "total" => $this->queries->count_violations_in($cur_run)
28
                , "added" => $this->queries->count_added_violations($prev_run, $cur_run)
29
                , "resolved" => $this->queries->count_resolved_violations($prev_run, $cur_run)
30
                ]
31
            , "rules" => array_map
32
                ( function($rule) use ($cur_run, $prev_run) {
33
                    $rule_info = $this->queries->rule_info($rule);
34
                    return
35
                        [ "rule" => $rule_info["rule"]
36
                        , "explanation" => $rule_info["explanation"]
37
                        , "violations" =>
38
                            [ "total" => $this->queries->count_violations_in($cur_run, $rule)
39
                            , "added" => $this->queries->count_added_violations($prev_run, $cur_run, $rule)
40
                            , "resolved" => $this->queries->count_resolved_violations($prev_run, $cur_run, $rule)
41
                            , "list" => $this->queries->violations_of($rule, $cur_run)
42
                            ]
43
                        ];
44
                }
45
                , $this->queries->analyzed_rules($cur_run)
46
                )
47
            ];
48
    }
49
}
50