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

MicrotimePlugin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 16.22 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 6
loc 37
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B renderTab() 6 29 5
A renderJs() 0 4 1

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\Rich;
4
5
use Kint\Object\Representation\MicrotimeRepresentation;
6
use Kint\Object\Representation\Representation;
7
use Kint\Utils;
8
9
class MicrotimePlugin extends Plugin implements TabPluginInterface
10
{
11
    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...
12
    {
13
        if (!($r instanceof MicrotimeRepresentation)) {
14
            return false;
15
        }
16
17
        $out = $r->getDateTime()->format('Y-m-d H:i:s.u');
18 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...
19
            $out .= "\n<b>SINCE LAST CALL:</b> <b class=\"kint-microtime-lap\">".round($r->lap, 4).'</b>s.';
20
        }
21
        if ($r->total !== null) {
22
            $out .= "\n<b>SINCE START:</b> ".round($r->total, 4).'s.';
23
        }
24 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...
25
            $out .= "\n<b>AVERAGE DURATION:</b> <span class=\"kint-microtime-avg\">".round($r->avg, 4).'</span>s.';
26
        }
27
28
        $bytes = Utils::getHumanReadableBytes($r->mem);
29
        $out .= "\n<b>MEMORY USAGE:</b> ".$r->mem.' bytes ('.round($bytes['value'], 3).' '.$bytes['unit'].')';
30
        $bytes = Utils::getHumanReadableBytes($r->mem_real);
31
        $out .= ' (real '.round($bytes['value'], 3).' '.$bytes['unit'].')';
32
33
        $bytes = Utils::getHumanReadableBytes($r->mem_peak);
34
        $out .= "\n<b>PEAK MEMORY USAGE:</b> ".$r->mem_peak.' bytes ('.round($bytes['value'], 3).' '.$bytes['unit'].')';
35
        $bytes = Utils::getHumanReadableBytes($r->mem_peak_real);
36
        $out .= ' (real '.round($bytes['value'], 3).' '.$bytes['unit'].')';
37
38
        return '<pre data-kint-microtime-group="'.$r->group.'">'.$out.'</pre>';
39
    }
40
41
    public static function renderJs()
42
    {
43
        return file_get_contents(KINT_DIR.'/resources/compiled/rich_microtime.js');
44
    }
45
}
46