Test Setup Failed
Push — test ( 2056fb...8efaca )
by Jonathan
03:13
created

MicrotimePlugin::renderTab()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 33
Code Lines 22

Duplication

Lines 6
Ratio 18.18 %

Importance

Changes 0
Metric Value
cc 5
eloc 22
nc 9
nop 1
dl 6
loc 33
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Renderer\Rich;
4
5
use Kint\Object\Representation\MicrotimeRepresentation;
6
use Kint\Object\Representation\Representation;
7
8
class MicrotimePlugin extends Plugin implements TabPluginInterface
9
{
10
    public function renderTab(Representation $r)
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...
11
    {
12
        if (!($r instanceof MicrotimeRepresentation)) {
13
            return false;
14
        }
15
16
        $out = $r->getDateTime()->format('Y-m-d H:i:s.u');
17 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...
18
            $out .= "\n<b>SINCE LAST CALL:</b> <b class=\"kint-microtime-lap\">".round($r->lap, 4).'</b>s.';
19
        }
20
        if ($r->total !== null) {
21
            $out .= "\n<b>SINCE START:</b> ".round($r->total, 4).'s.';
22
        }
23 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...
24
            $out .= "\n<b>AVERAGE DURATION:</b> <span class=\"kint-microtime-avg\">".round($r->avg, 4).'</span>s.';
25
        }
26
27
        $unit = array('B', 'KB', 'MB', 'GB', 'TB');
28
29
        $out .= "\n<b>MEMORY USAGE:</b> ".$r->mem.' bytes (';
30
        $i = floor(log($r->mem, 1024));
31
        $out .= round($r->mem / pow(1024, $i), 3).' '.$unit[$i].')';
32
        $i = floor(log($r->mem_real, 1024));
33
        $out .= ' (real '.round($r->mem_real / pow(1024, $i), 3).' '.$unit[$i].')';
34
35
        $out .= "\n<b>PEAK MEMORY USAGE:</b> ".$r->mem_peak.' bytes (';
36
        $i = floor(log($r->mem_peak, 1024));
37
        $out .= round($r->mem_peak / pow(1024, $i), 3).' '.$unit[$i].')';
38
        $i = floor(log($r->mem_peak_real, 1024));
39
        $out .= ' (real '.round($r->mem_peak_real / pow(1024, $i), 3).' '.$unit[$i].')';
40
41
        return '<pre data-kint-microtime-group="'.$r->group.'">'.$out.'</pre>';
42
    }
43
44
    public static function renderJs()
45
    {
46
        return file_get_contents(KINT_DIR.'/resources/compiled/rich_microtime.js');
47
    }
48
}
49