Kint_Renderer_Rich_Source   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 50
Duplicated Lines 28 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 14
loc 50
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
C render() 14 47 13

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
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