Kint_Renderer_Rich_Microtime::render()   C
last analyzed

Complexity

Conditions 7
Paths 17

Size

Total Lines 38
Code Lines 24

Duplication

Lines 6
Ratio 15.79 %

Importance

Changes 0
Metric Value
cc 7
eloc 24
nc 17
nop 1
dl 6
loc 38
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
class Kint_Renderer_Rich_Microtime extends Kint_Renderer_Rich_Plugin
0 ignored issues
show
Coding Style introduced by
Kint_Renderer_Rich_Microtime does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
4
{
5
    public function render($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...
6
    {
7
        if (!($r instanceof Kint_Object_Representation_Microtime)) {
8
            return false;
9
        }
10
11
        list($usec, $sec) = explode(' ', $r->contents);
12
13
        // '@' is used to prevent the dreaded timezone not set error
14
        $out = @date('Y-m-d H:i:s', $sec).'.'.substr($usec, 2, 4);
15 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...
16
            $out .= "\n<b>SINCE LAST CALL:</b> <b class=\"kint-microtime-lap\">".round($r->lap, 4).'</b>s.';
17
        }
18
        if ($r->total !== null) {
19
            $out .= "\n<b>SINCE START:</b> ".round($r->total, 4).'s.';
20
        }
21 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...
22
            $out .= "\n<b>AVERAGE DURATION:</b> <span class=\"kint-microtime-avg\">".round($r->avg, 4).'</span>s.';
23
        }
24
25
        $unit = array('B', 'KB', 'MB', 'GB', 'TB');
26
27
        $out .= "\n<b>MEMORY USAGE:</b> ".$r->mem.' bytes (';
28
        $i = floor(log($r->mem, 1024));
29
        $out .= round($r->mem / pow(1024, $i), 3).' '.$unit[$i].')';
30
        $i = floor(log($r->mem_real, 1024));
31
        $out .= ' (real '.round($r->mem_real / pow(1024, $i), 3).' '.$unit[$i].')';
32
33
        if ($r->mem_peak !== null && $r->mem_peak_real !== null) {
34
            $out .= "\n<b>PEAK MEMORY USAGE:</b> ".$r->mem_peak.' bytes (';
35
            $i = floor(log($r->mem_peak, 1024));
36
            $out .= round($r->mem_peak / pow(1024, $i), 3).' '.$unit[$i].')';
37
            $i = floor(log($r->mem_peak_real, 1024));
38
            $out .= ' (real '.round($r->mem_peak_real / pow(1024, $i), 3).' '.$unit[$i].')';
39
        }
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