Test Setup Failed
Push — next ( 738e04...b06172 )
by Jonathan
25:05
created

MicrotimePlugin::render()   B

Complexity

Conditions 6
Paths 17

Size

Total Lines 53
Code Lines 34

Duplication

Lines 12
Ratio 22.64 %

Importance

Changes 0
Metric Value
cc 6
eloc 34
nc 17
nop 1
dl 12
loc 53
rs 8.7155
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
use Kint\Utils;
8
9
class MicrotimePlugin extends Plugin
10
{
11
    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...
12
    {
13
        $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...
14
15
        if (!$r instanceof MicrotimeRepresentation) {
16
            return false;
17
        }
18
19
        $out = '';
20
21
        if ($o->depth == 0) {
22
            $out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
23
        }
24
25
        $out .= $this->renderer->renderHeader($o);
26
        $out .= $this->renderer->renderChildren($o).PHP_EOL;
27
28
        $indent = str_repeat(' ', ($o->depth + 1) * $this->renderer->indent_width);
29
30
        $out .= $indent.$this->renderer->colorType('TIME:').' ';
31
        $out .= $this->renderer->colorValue($r->getDateTime()->format('Y-m-d H:i:s.u')).PHP_EOL;
32
33 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...
34
            $out .= $indent.$this->renderer->colorType('SINCE LAST CALL:').' ';
35
            $out .= $this->renderer->colorValue(round($r->lap, 4).'s').'.'.PHP_EOL;
36
        }
37 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...
38
            $out .= $indent.$this->renderer->colorType('SINCE START:').' ';
39
            $out .= $this->renderer->colorValue(round($r->total, 4).'s').'.'.PHP_EOL;
40
        }
41 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...
42
            $out .= $indent.$this->renderer->colorType('AVERAGE DURATION:').' ';
43
            $out .= $this->renderer->colorValue(round($r->avg, 4).'s').'.'.PHP_EOL;
44
        }
45
46
        $bytes = Utils::getHumanReadableBytes($r->mem);
47
        $mem = $r->mem.' bytes ('.round($bytes['value'], 3).' '.$bytes['unit'].')';
48
        $bytes = Utils::getHumanReadableBytes($r->mem_real);
49
        $mem .= ' (real '.round($bytes['value'], 3).' '.$bytes['unit'].')';
50
51
        $out .= $indent.$this->renderer->colorType('MEMORY USAGE:').' ';
52
        $out .= $this->renderer->colorValue($mem).'.'.PHP_EOL;
53
54
        $bytes = Utils::getHumanReadableBytes($r->mem_peak);
55
        $mem = $r->mem_peak.' bytes ('.round($bytes['value'], 3).' '.$bytes['unit'].')';
56
        $bytes = Utils::getHumanReadableBytes($r->mem_peak_real);
57
        $mem .= ' (real '.round($bytes['value'], 3).' '.$bytes['unit'].')';
58
59
        $out .= $indent.$this->renderer->colorType('PEAK MEMORY USAGE:').' ';
60
        $out .= $this->renderer->colorValue($mem).'.'.PHP_EOL;
61
62
        return $out;
63
    }
64
}
65