Completed
Push — develop ( 505b4c...31ac0b )
by Seth
03:45
created

HeatMap   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 118
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
D getLevel() 0 113 14
1
<?php
2
3
namespace smtech\GradingAnalytics\HeatMap;
4
5
class HeatMap
6
{
7
    private static $levels = [];
8
9
    public static function getLevel($params, $smarty)
1 ignored issue
show
Unused Code introduced by
The parameter $smarty is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
10
    {
11
        $key = false;
12
        $value = false;
13
        foreach ($params as $k => $v) {
14
            switch ($k) {
15
                case 'key':
16
                    $key = $v;
17
                    break;
18
                case 'value':
19
                    $value = $v;
20
                    break;
21
            }
22
        }
23
        if ($key === false || $value == false) {
24
            return "";
25
        }
26
27
        if (empty(static::$levels)) {
0 ignored issues
show
Bug introduced by
Since $levels is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $levels to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
28
            static::$levels = array(
0 ignored issues
show
Bug introduced by
Since $levels is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $levels to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
29
                'average_grading_turn_around' => array(
30
                    'warning' => array(
31
                        new Level(3, 14, Level::$GREATER_THAN),
32
                        new Level(2, 7, Level::$GREATER_THAN)
33
                    ),
34
                    'highlight' => array(
35
                        new Level (3, 3, Level::$LESS_THAN),
36
                        new Level (2, 7, Level::$LESS_THAN)
37
                    )
38
                ),
39
                'average_assignment_lead_time' => array(
40
                    'warning' => array(
41
                        new Level(3, 1, Level::$LESS_THAN),
42
                        new Level(2, 2, Level::$LESS_THAN)
43
                    ),
44
                    'highlight' => array(
45
                        new Level(3, 10, Level::$GREATER_THAN),
46
                        new Level(2, 7, Level::$GREATER_THAN)
47
                    )
48
                ),
49
                'average_submissions_graded' => array(
50
                    'warning' => array(
51
                        new Level(3, 0.5, Level::$LESS_THAN),
52
                        new Level(2, 0.75, Level::$LESS_THAN)
53
                    ),
54
                    'highlight' => array(
55
                        new Level(3, 1.0, Level::$GREATER_THAN_OR_EQUAL),
56
                        new Level(2, 0.9, Level::$GREATER_THAN)
57
                    )
58
                ),
59
                'dateless_assignment_count' => array(
60
                    'warning' => array(
61
                        new Level(3, 20, Level::$GREATER_THAN),
62
                        new Level(2, 10, Level::$GREATER_THAN)
63
                    ),
64
                    'highlight' => array(
65
                        new Level(3, 1, Level::$LESS_THAN),
66
                        new Level(2, 5, Level::$LESS_THAN)
67
                    )
68
                ),
69
                'gradeable_assignment_count' => array(
70
                    'warning' => array(
71
                        new Level(3, 0, Level::$LESS_THAN_OR_EQUAL)
72
                    )
73
                ),
74
                'graded_assignment_count' => array(
75
                    'warning' => array(
76
                        new Level(3, 0, Level::$LESS_THAN_OR_EQUAL)
77
                    )
78
                ),
79
                'created_after_due_count' => array(
80
                    'warning' => array(
81
                        new Level(3, 10, Level::$GREATER_THAN),
82
                        new Level(2, 5, Level::$GREATER_THAN)
83
                    ),
84
                    'highlight' => array(
85
                        new Level(3, 1, Level::$LESS_THAN),
86
                        new Level(2, 5, Level::$LESS_THAN)
87
                    )
88
                ),
89
                'zero_point_assignment_count' => array(
90
                    'warning' => array(
91
                        new Level(3, 10, Level::$GREATER_THAN_OR_EQUAL),
92
                        new Level(2, 0, Level::$GREATER_THAN)
93
                    )
94
                )
95
            );
96
        }
97
98
        foreach (static::$levels[$key] as $mode => $modeLevels) {
0 ignored issues
show
Bug introduced by
Since $levels is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $levels to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
99
            foreach ($modeLevels as $level) {
100
                $match = false;
101
                switch ($level->comparison) {
102
                    case Level::$GREATER_THAN:
103
                        $match = $value > $level->value;
104
                        break;
105
                    case Level::$GREATER_THAN_OR_EQUAL:
106
                        $match = $value >= $level->value;
107
                        break;
108
                    case Level::$LESS_THAN:
109
                        $match = $value < $level->value;
110
                        break;
111
                    case Level::$LESS_THAN_OR_EQUAL:
112
                        $match = $value <= $level->value;
113
                        break;
114
                }
115
                if ($match) {
116
                    return " class=\"$mode level-{$level->level}\"";
117
                }
118
            }
119
        }
120
        return "";
121
    }
122
}
123