Conditions | 14 |
Paths | 100 |
Total Lines | 113 |
Code Lines | 79 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
9 | public static function getLevel($params, $smarty) |
||
1 ignored issue
–
show
|
|||
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(self::$levels)) { |
||
28 | self::$levels = [ |
||
29 | 'average_grading_turn_around' => [ |
||
30 | 'warning' => [ |
||
31 | new Level(3, 14, Level::$GREATER_THAN), |
||
32 | new Level(2, 7, Level::$GREATER_THAN) |
||
33 | ], |
||
34 | 'highlight' => [ |
||
35 | new Level (3, 3, Level::$LESS_THAN), |
||
36 | new Level (2, 7, Level::$LESS_THAN) |
||
37 | ] |
||
38 | ], |
||
39 | 'average_assignment_lead_time' => [ |
||
40 | 'warning' => [ |
||
41 | new Level(3, 1, Level::$LESS_THAN), |
||
42 | new Level(2, 2, Level::$LESS_THAN) |
||
43 | ], |
||
44 | 'highlight' => [ |
||
45 | new Level(3, 10, Level::$GREATER_THAN), |
||
46 | new Level(2, 7, Level::$GREATER_THAN) |
||
47 | ] |
||
48 | ], |
||
49 | 'average_submissions_graded' => [ |
||
50 | 'warning' => [ |
||
51 | new Level(3, 0.5, Level::$LESS_THAN), |
||
52 | new Level(2, 0.75, Level::$LESS_THAN) |
||
53 | ], |
||
54 | 'highlight' => [ |
||
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' => [ |
||
60 | 'warning' => [ |
||
61 | new Level(3, 20, Level::$GREATER_THAN), |
||
62 | new Level(2, 10, Level::$GREATER_THAN) |
||
63 | ], |
||
64 | 'highlight' => [ |
||
65 | new Level(3, 1, Level::$LESS_THAN), |
||
66 | new Level(2, 5, Level::$LESS_THAN) |
||
67 | ] |
||
68 | ], |
||
69 | 'gradeable_assignment_count' => [ |
||
70 | 'warning' => [ |
||
71 | new Level(3, 0, Level::$LESS_THAN_OR_EQUAL) |
||
72 | ] |
||
73 | ], |
||
74 | 'graded_assignment_count' => [ |
||
75 | 'warning' => [ |
||
76 | new Level(3, 0, Level::$LESS_THAN_OR_EQUAL) |
||
77 | ] |
||
78 | ], |
||
79 | 'created_after_due_count' => [ |
||
80 | 'warning' => [ |
||
81 | new Level(3, 10, Level::$GREATER_THAN), |
||
82 | new Level(2, 5, Level::$GREATER_THAN) |
||
83 | ], |
||
84 | 'highlight' => [ |
||
85 | new Level(3, 1, Level::$LESS_THAN), |
||
86 | new Level(2, 5, Level::$LESS_THAN) |
||
87 | ] |
||
88 | ], |
||
89 | 'zero_point_assignment_count' => [ |
||
90 | 'warning' => [ |
||
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 (self::$levels[$key] as $mode => $modeLevels) { |
||
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 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.