Conditions | 8 |
Paths | 33 |
Total Lines | 61 |
Code Lines | 39 |
Lines | 12 |
Ratio | 19.67 % |
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 |
||
10 | public function render(BasicObject $o) |
||
|
|||
11 | { |
||
12 | $r = $o->getRepresentation('microtime'); |
||
13 | |||
14 | if (!$r instanceof MicrotimeRepresentation) { |
||
15 | return false; |
||
16 | } |
||
17 | |||
18 | $out = ''; |
||
19 | |||
20 | if ($o->depth == 0) { |
||
21 | $out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL; |
||
22 | } |
||
23 | |||
24 | $out .= $this->renderer->renderHeader($o); |
||
25 | $out .= $this->renderer->renderChildren($o).PHP_EOL; |
||
26 | |||
27 | list($usec, $sec) = explode(' ', $r->contents); |
||
28 | |||
29 | $indent = str_repeat(' ', ($o->depth + 1) * $this->renderer->indent_width); |
||
30 | |||
31 | $out .= $indent.$this->renderer->colorType('TIME:').' '; |
||
32 | $out .= $this->renderer->colorValue(@date('Y-m-d H:i:s', $sec).'.'.substr($usec, 2, 4)).PHP_EOL; |
||
33 | |||
34 | View Code Duplication | if ($r->lap !== null) { |
|
35 | $out .= $indent.$this->renderer->colorType('SINCE LAST CALL:').' '; |
||
36 | $out .= $this->renderer->colorValue(round($r->lap, 4).'s').'.'.PHP_EOL; |
||
37 | } |
||
38 | View Code Duplication | if ($r->total !== null) { |
|
39 | $out .= $indent.$this->renderer->colorType('SINCE START:').' '; |
||
40 | $out .= $this->renderer->colorValue(round($r->total, 4).'s').'.'.PHP_EOL; |
||
41 | } |
||
42 | View Code Duplication | if ($r->avg !== null) { |
|
43 | $out .= $indent.$this->renderer->colorType('AVERAGE DURATION:').' '; |
||
44 | $out .= $this->renderer->colorValue(round($r->avg, 4).'s').'.'.PHP_EOL; |
||
45 | } |
||
46 | |||
47 | $unit = array('B', 'KB', 'MB', 'GB', 'TB'); |
||
48 | |||
49 | $mem = $r->mem.' bytes ('; |
||
50 | $i = floor(log($r->mem, 1024)); |
||
51 | $mem .= round($r->mem / pow(1024, $i), 3).' '.$unit[$i].')'; |
||
52 | $i = floor(log($r->mem_real, 1024)); |
||
53 | $mem .= ' (real '.round($r->mem_real / pow(1024, $i), 3).' '.$unit[$i].')'; |
||
54 | |||
55 | $out .= $indent.$this->renderer->colorType('MEMORY USAGE:').' '; |
||
56 | $out .= $this->renderer->colorValue($mem).'.'.PHP_EOL; |
||
57 | |||
58 | if ($r->mem_peak !== null && $r->mem_peak_real !== null) { |
||
59 | $mem = $r->mem_peak.' bytes ('; |
||
60 | $i = floor(log($r->mem_peak, 1024)); |
||
61 | $mem .= round($r->mem_peak / pow(1024, $i), 3).' '.$unit[$i].')'; |
||
62 | $i = floor(log($r->mem_peak_real, 1024)); |
||
63 | $mem .= ' (real '.round($r->mem_peak_real / pow(1024, $i), 3).' '.$unit[$i].')'; |
||
64 | |||
65 | $out .= $indent.$this->renderer->colorType('PEAK MEMORY USAGE:').' '; |
||
66 | $out .= $this->renderer->colorValue($mem).'.'.PHP_EOL; |
||
67 | } |
||
68 | |||
69 | return $out; |
||
70 | } |
||
71 | } |
||
72 |
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.