Graph   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 2
eloc 16
c 0
b 0
f 0
dl 0
loc 42
rs 10
ccs 10
cts 11
cp 0.9091

1 Method

Rating   Name   Duplication   Size   Complexity  
A graph() 0 33 2
1
<?php
2
3
namespace mQueue\View\Helper;
4
5
use mQueue\Model\User;
6
use Zend_View_Helper_Abstract;
7
8
class Graph extends Zend_View_Helper_Abstract
9
{
10
    /**
11
     * Returns a graph for everybody or single user
12
     *
13
     * @param User $user
14
     *
15
     * @return string
16
     */
17 1
    public function graph(User $user = null)
18
    {
19 1
        $params = ['controller' => 'status', 'action' => 'graph'];
20 1
        if ($user) {
21
            $params['user'] = $user->id;
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on mQueue\Model\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
        }
23 1
        $url = $this->view->serverUrl() . $this->view->url($params, 'default');
24
25
        $js = <<<STRING
26
        $(document).ready(function() {
27
            const refreshGraph = function() {
28
                const percentage = $('#graph_percent').is(':checked') ? '?percent=1' : '';
29 1
                $.get('$url' + percentage, function (chart) {
30
                    chart = $.parseJSON(chart);
31
                    $('#chart_container').highcharts(chart);
32
                });
33
            };
34
35
            $('#graph_percent').change(refreshGraph);
36
            refreshGraph();
37
38
        });
39
STRING;
40
41 1
        $html = '<div id="chart_container"  style="min-height: 400px"></div>
42
                <input type="checkbox" name="graph_percent" id="graph_percent" value="1">
43
                <label for="graph_percent">Show graph as stacked percentage</label>';
44
45 1
        $this->view->headScript()
46 1
            ->appendFile('/js/min/highcharts.js')
47 1
            ->appendScript($js);
48
49 1
        return $html;
50
    }
51
}
52