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

MicrotimePlugin   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 18.75 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 12
loc 64
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 12 61 8

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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