Test Setup Failed
Push — test ( b54d60...8334a3 )
by Jonathan
03:33
created

MicrotimePlugin::render()   B

Complexity

Conditions 8
Paths 33

Size

Total Lines 61
Code Lines 39

Duplication

Lines 12
Ratio 19.67 %

Importance

Changes 0
Metric Value
cc 8
eloc 39
nc 33
nop 1
dl 12
loc 61
rs 7.0047
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace Kint\Renderer\Text;
4
5
use Kint\Object\BasicObject;
6
use Kint\Object\Representation\MicrotimeRepresentation;
7
8
class MicrotimePlugin extends Plugin
9
{
10
    public function render(BasicObject $o)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
11
    {
12
        $r = $o->getRepresentation('microtime');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

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.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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