| 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(static::$levels)) { |
||
| 28 | static::$levels = array( |
||
| 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) { |
||
| 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.