Completed
Branch master (2d0ab0)
by Adrien
07:23
created

Graph   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B graph() 0 34 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
     * @param \mQueue\Model\User $user
0 ignored issues
show
Documentation introduced by
Should the type for parameter $user not be null|User?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
13
     * @return string
14
     */
15 1
    public function graph(\mQueue\Model\User $user = null)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
16
    {
17 1
        $params = ['controller' => 'status', 'action' => 'graph'];
18 1
        if ($user) {
19
            $params['user'] = $user->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<mQueue\Model\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
20
        }
21 1
        $url = $this->view->serverUrl() . $this->view->url($params, 'default');
22
23
        $js = <<<STRING
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $js. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
24
        $(document).ready(function() {
25
            var refreshGraph = function() {
26
                var percentage = $('#graph_percent').is(':checked') ? '?percent=1' : '';
27 1
                $.get('$url' + percentage, function (chart) {
28
                    chart = $.parseJSON(chart);
29
                    $('#chart_container').highcharts(chart);
30
                });
31
            };
32
33
            $('#graph_percent').change(refreshGraph);
34
            refreshGraph();
35
36
        });
37
STRING;
38
39 1
        $html = '<div id="chart_container"  style="min-height: 400px"></div>
40
                <input type="checkbox" name="graph_percent" id="graph_percent" value="1">
41
                <label for="graph_percent">Show graph as stacked percentage</label>';
42
43 1
        $this->view->headScript()
44 1
                ->appendFile('/js/min/highcharts.js')
45 1
                ->appendScript($js);
46
47 1
        return $html;
48
    }
49
}
50