Kint_Renderer_Text_Trace::render()   D
last analyzed

Complexity

Conditions 17
Paths 182

Size

Total Lines 78
Code Lines 46

Duplication

Lines 14
Ratio 17.95 %

Importance

Changes 0
Metric Value
cc 17
eloc 46
nc 182
nop 1
dl 14
loc 78
rs 4.7847
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
class Kint_Renderer_Text_Trace extends Kint_Renderer_Text_Plugin
0 ignored issues
show
Coding Style introduced by
Kint_Renderer_Text_Trace 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($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...
6
    {
7
        $out = '';
8
9
        if ($o->depth == 0) {
10
            $out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
11
        }
12
13
        $out .= $this->renderer->renderHeader($o).':'.PHP_EOL;
14
15
        $indent = str_repeat(' ', ($o->depth + 1) * $this->renderer->indent_width);
16
17
        $i = 1;
18
        foreach ($o->value->contents as $frame) {
19
            $framedesc = $indent.str_pad($i.': ', 4, ' ');
20
21
            if ($frame->trace['file']) {
22
                $framedesc .= $this->renderer->ideLink($frame->trace['file'], $frame->trace['line']).PHP_EOL;
23
            } else {
24
                $framedesc .= 'PHP internal call'.PHP_EOL;
25
            }
26
27
            $framedesc .= $indent.'    ';
28
29
            if ($frame->trace['class']) {
30
                $framedesc .= $this->renderer->escape($frame->trace['class']);
31
32
                if ($frame->trace['object']) {
33
                    $framedesc .= $this->renderer->escape('->');
34
                } else {
35
                    $framedesc .= '::';
36
                }
37
            }
38
39
            if (is_string($frame->trace['function'])) {
40
                $framedesc .= $this->renderer->escape($frame->trace['function']).'(...)';
41
            } elseif ($frame->trace['function'] instanceof Kint_Object_Method) {
42
                $framedesc .= $this->renderer->escape($frame->trace['function']->getName());
43
                $framedesc .= '('.$this->renderer->escape($frame->trace['function']->getParams()).')';
44
            }
45
46
            $out .= $this->renderer->colorType($framedesc).PHP_EOL.PHP_EOL;
47
48
            if ($source = $frame->getRepresentation('source')) {
49
                $line_wanted = $source->line;
0 ignored issues
show
Coding Style introduced by
$line_wanted 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...
50
                $source = $source->source;
51
52
                // Trim empty lines from the start and end of the source
53 View Code Duplication
                foreach ($source as $linenum => $line) {
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...
54
                    if (trim($line) || $linenum === $line_wanted) {
0 ignored issues
show
Coding Style introduced by
$line_wanted 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...
55
                        break;
56
                    } else {
57
                        unset($source[$linenum]);
58
                    }
59
                }
60
61 View Code Duplication
                foreach (array_reverse($source, true) as $linenum => $line) {
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...
62
                    if (trim($line) || $linenum === $line_wanted) {
0 ignored issues
show
Coding Style introduced by
$line_wanted 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...
63
                        break;
64
                    } else {
65
                        unset($source[$linenum]);
66
                    }
67
                }
68
69
                foreach ($source as $lineno => $line) {
70
                    if ($lineno == $line_wanted) {
0 ignored issues
show
Coding Style introduced by
$line_wanted 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...
71
                        $out .= $indent.$this->renderer->colorValue($this->renderer->escape($line)).PHP_EOL;
72
                    } else {
73
                        $out .= $indent.$this->renderer->escape($line).PHP_EOL;
74
                    }
75
                }
76
            }
77
78
            ++$i;
79
        }
80
81
        return $out;
82
    }
83
}
84