Passed
Push — master ( 2acbdd...490d36 )
by William
07:42
created

ReportsHelper   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 86.44%

Importance

Changes 0
Metric Value
eloc 53
dl 0
loc 103
ccs 51
cts 59
cp 0.8644
rs 10
c 0
b 0
f 0
wmc 16

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getLineChartData() 0 9 2
A createReportsLinks() 0 9 2
A linkToReportFromIncident() 0 6 1
A entriesFromIncidents() 0 15 3
A getChartArray() 0 18 3
A getStacktracesForIncidents() 0 19 3
A __construct() 0 3 1
A linkToReport() 0 6 1
1
<?php
2
3
/* vim: set expandtab sw=4 ts=4 sts=4: */
4
5
namespace App\View\Helper;
6
7
use App\Utility\Sanitize;
0 ignored issues
show
Bug introduced by
The type App\Utility\Sanitize was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use App\View\Helper\AppHelper;
9
use Cake\Utility\Inflector;
10
use Cake\View\View;
11
12
class ReportsHelper extends AppHelper
13
{
14
    public $helpers = ['Incidents'];
15
16 7
    public function __construct(View $view, $settings = [])
17
    {
18 7
        parent::__construct($view, $settings);
19 7
    }
20
21 2
    public function entriesFromIncidents($entries, $totalCount, $key)
22
    {
23
        //$entries = Sanitize::clean($entries);
24 2
        $values = [];
25 2
        foreach ($entries as $entry) {
26 2
            $values[] = "$entry[$key] <span class='count'>("
27 2
                . $entry['count'] . ')</span>';
28
        }
29 2
        $fullString = implode(', ', $values);
30 2
        $remaining = $totalCount - count($values);
31 2
        if ($remaining) {
32
            $fullString .= " <small>and $remaining others</small>";
33
        }
34
35 2
        return $fullString;
36
    }
37
38 1
    public function createReportsLinks($reports)
39
    {
40 1
        $links = [];
41 1
        foreach ($reports as $report) {
42 1
            $links[] = $this->linkToReport($report);
43
        }
44 1
        $string = implode(', ', $links);
45
46 1
        return $string;
47
    }
48
49 3
    public function linkToReport($report)
50
    {
51 3
        $reportId = $report['id'];
52 3
        $link = '<a href=/' . BASE_DIR . "reports/view/$reportId>#$reportId</a>";
53
54 3
        return $link;
55
    }
56
57 1
    public function linkToReportFromIncident($incident)
58
    {
59 1
        $reportId = $incident['report_id'];
60 1
        $link = '<a href=/' . BASE_DIR . "reports/view/$reportId>#$reportId</a>";
61
62 1
        return $link;
63
    }
64
65 1
    public function getStacktracesForIncidents($incidents)
66
    {
67 1
        $count = 0;
68 1
        $html = '<div class="row">';
69 1
        foreach ($incidents as $incident) {
70 1
            $class = 'well span5';
71
72 1
            if ($count % 2 == 1) {
73
                $class .= ' ';
74
            } else {
75 1
                $html .= "</div><div class='row'>";
76
            }
77
78 1
            $html .= $this->Incidents->getStacktrace($incident, $class);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->Incidents->getSta...race($incident, $class) targeting Cake\View\Helper::__call() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
The method getStacktrace() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
            $html .= $this->Incidents->/** @scrutinizer ignore-call */ getStacktrace($incident, $class);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property Incidents does not exist on App\View\Helper\ReportsHelper. Since you implemented __get, consider adding a @property annotation.
Loading history...
79 1
            ++$count;
80
        }
81 1
        $html .= '</div>';
82
83 1
        return $html;
84
    }
85
86 1
    public function getChartArray($arrayName, $columns, $relatedEntries)
87
    {
88 1
        $html = "var $arrayName = [], chart = {};";
89 1
        foreach ($columns as $column) {
90 1
            $column = htmlspecialchars($column, ENT_QUOTES | ENT_HTML5);
91 1
            $html .= 'chart = {};';
92 1
            $html .= "chart.name = '$column';";
93 1
            $html .= "chart.title = '" . Inflector::humanize($column) . "';";
94 1
            $html .= 'chart.labels = []; chart.values = [];';
95 1
            foreach ($relatedEntries[$column] as $entry) {
96 1
                $count = $entry['count'];
97 1
                $html .= "chart.labels.push('$entry[$column] ($count)');";
98 1
                $html .= "chart.values.push($count);";
99
            }
100 1
            $html .= "$arrayName.push(chart);";
101
        }
102
103 1
        return $html;
104
    }
105
106
    public function getLineChartData($arrayName, $entries)
107
    {
108
        $html = "var $arrayName = [];";
109
        foreach ($entries as $entry) {
110
            $html .= "$arrayName.push(['" . $entry['date'] . "', "
111
                    . $entry['count'] . ']);';
112
        }
113
114
        return $html;
115
    }
116
}
117