Conditions | 14 |
Paths | 22 |
Total Lines | 54 |
Code Lines | 32 |
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 |
||
81 | protected function drawGraph($data) |
||
82 | { |
||
83 | $chars = 60; |
||
84 | |||
85 | if (count($data) > $chars) { |
||
86 | $scaleX = floor(count($data) / $chars); |
||
87 | |||
88 | $scaledData = []; |
||
89 | |||
90 | for ($i = 0; $i < $chars; $i++) { |
||
91 | $segment = array_slice($data, 1 + ($scaleX * $i) * -1, $scaleX); |
||
92 | |||
93 | $total = 0; |
||
94 | foreach ($segment as $value) { |
||
95 | $total += $value; |
||
96 | } |
||
97 | |||
98 | $value = $total; |
||
99 | |||
100 | $scaledData[] = round($value); |
||
101 | } |
||
102 | |||
103 | $data = array_reverse($scaledData); |
||
|
|||
104 | } |
||
105 | |||
106 | $minY = min(array_values($data)); |
||
107 | $maxY = max(array_values($data)); |
||
108 | |||
109 | $graph = ''; |
||
110 | |||
111 | foreach ($data as $time => $value) { |
||
112 | if ($maxY > 0) { |
||
113 | $percent = round($value * 100 / $maxY); |
||
114 | } else { |
||
115 | $percent = 0; |
||
116 | } |
||
117 | |||
118 | $char = '▁'; |
||
119 | |||
120 | if ($percent > 75 && $percent <= 100) { |
||
121 | $char = '▇'; |
||
122 | } else if ($percent > 50 && $percent <= 75) { |
||
123 | $char = '▅'; |
||
124 | } else if ($percent > 25 && $percent <= 50) { |
||
125 | $char = '▃'; |
||
126 | } else if ($percent > 0 && $percent <= 25) { |
||
127 | $char = '▂'; |
||
128 | } |
||
129 | |||
130 | $graph .= $char; |
||
131 | } |
||
132 | |||
133 | return $graph; |
||
134 | } |
||
135 | |||
190 |