Kint_Renderer_Rich_Source::render()   C
last analyzed

Complexity

Conditions 13
Paths 73

Size

Total Lines 47
Code Lines 28

Duplication

Lines 14
Ratio 29.79 %

Importance

Changes 0
Metric Value
cc 13
eloc 28
nc 73
nop 1
dl 14
loc 47
rs 5.0999
c 0
b 0
f 0

How to fix   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_Rich_Source extends Kint_Renderer_Rich_Plugin
0 ignored issues
show
Coding Style introduced by
Kint_Renderer_Rich_Source 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_Source) || empty($r->source)) {
8
            return false;
9
        }
10
11
        $source = $r->source;
12
13
        // Trim empty lines from the start and end of the source
14 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...
15
            if (trim($line) || $linenum === $r->line) {
16
                break;
17
            } else {
18
                unset($source[$linenum]);
19
            }
20
        }
21
22 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...
23
            if (trim($line) || $linenum === $r->line) {
24
                break;
25
            } else {
26
                unset($source[$linenum]);
27
            }
28
        }
29
30
        $start = '';
31
        $highlight = '';
32
        $end = '';
33
34
        foreach ($source as $linenum => $line) {
35
            if ($linenum < $r->line) {
36
                $start .= $line."\n";
37
            } elseif ($linenum === $r->line) {
38
                $highlight = '<div class="kint-highlight">'.$this->renderer->escape($line).'</div>';
39
            } else {
40
                $end .= $line."\n";
41
            }
42
        }
43
44
        $output = $this->renderer->escape($start).$highlight.$this->renderer->escape(substr($end, 0, -1));
45
46
        if ($output) {
47
            reset($source);
48
49
            return '<pre class="kint-source" data-kint-sourcerange="@@ '.((int) key($source)).','.count($source).' @@">'.$output.'</pre>';
50
        }
51
    }
52
}
53