Kint_Renderer_Rich_Plugin::renderLockedHeader()   D
last analyzed

Complexity

Conditions 13
Paths 288

Size

Total Lines 51
Code Lines 26

Duplication

Lines 26
Ratio 50.98 %

Importance

Changes 0
Metric Value
cc 13
eloc 26
nc 288
nop 2
dl 26
loc 51
rs 4.1971
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
abstract class Kint_Renderer_Rich_Plugin
0 ignored issues
show
Coding Style introduced by
Kint_Renderer_Rich_Plugin 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...
Coding Style introduced by
Kint_Renderer_Rich_Plugin does not seem to conform to the naming convention (^Abstract|Factory$).

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
    protected $renderer;
6
7
    public function __construct(Kint_Renderer_Rich $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...
8
    {
9
        $this->renderer = $r;
10
    }
11
12
    /**
13
     * Renders a locked header.
14
     *
15
     * This is a placeholder until Kint 3 when it can be renamed to
16
     * renderLockedHeader after the deprecated static method is removed
17
     */
18
    public function renderHeaderLocked(Kint_Object $o, $content)
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...
19
    {
20
        $header = '<dt class="kint-parent kint-locked">';
21
22 View Code Duplication
        if (Kint_Renderer_Rich::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) {
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...
Comprehensibility introduced by
Avoid variables with short names like $ap. 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...
23
            $header .= '<span class="kint-access-path-trigger" title="Show access path">&rlarr;</span>';
24
        }
25
26
        $header .= '<span class="kint-popup-trigger" title="Open in new window">&rarr;</span><nav></nav>';
27
28
        if (($s = $o->getModifiers()) !== null) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $s. 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...
29
            $header .= '<var>'.$s.'</var> ';
30
        }
31
32 View Code Duplication
        if (($s = $o->getName()) !== 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...
33
            $header .= '<dfn>'.$this->renderer->escape($s).'</dfn> ';
34
35
            if ($s = $o->getOperator()) {
36
                $header .= $this->renderer->escape($s, 'ASCII').' ';
0 ignored issues
show
Documentation introduced by
'ASCII' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
37
            }
38
        }
39
40
        if (($s = $o->getType()) !== null) {
41
            $s = $this->renderer->escape($s);
42
43
            if ($o->reference) {
44
                $s = '&amp;'.$s;
45
            }
46
47
            $header .= '<var>'.$s.'</var> ';
48
        }
49
50 View Code Duplication
        if (($s = $o->getSize()) !== 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...
51
            $header .= '('.$this->renderer->escape($s).') ';
52
        }
53
54
        $header .= $content;
55
56
        if (!empty($ap)) {
57
            $header .= '<div class="access-path">'.$this->renderer->escape($ap).'</div>';
58
        }
59
60
        return $header.'</dt>';
61
    }
62
63
    public static function renderLockedHeader(Kint_Object $o, $content)
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...
64
    {
65
        static $show_dep = true;
66
67 View Code Duplication
        if ($show_dep) {
0 ignored issues
show
Coding Style introduced by
$show_dep 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...
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...
68
            trigger_error('Kint_Renderer_Rich_Plugin::renderLockedHeader() is deprecated and will be removed in Kint 3.0. Use renderHeaderLocked instead.', KINT_PHP53 ? E_USER_DEPRECATED : E_USER_NOTICE);
69
            $show_dep = false;
0 ignored issues
show
Coding Style introduced by
$show_dep 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...
70
        }
71
72
        $header = '<dt class="kint-parent kint-locked">';
73
74 View Code Duplication
        if (Kint_Renderer_Rich::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) {
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...
Comprehensibility introduced by
Avoid variables with short names like $ap. 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...
75
            $header .= '<span class="kint-access-path-trigger" title="Show access path">&rlarr;</span>';
76
        }
77
78
        $header .= '<span class="kint-popup-trigger" title="Open in new window">&rarr;</span><nav></nav>';
79
80
        if (($s = $o->getModifiers()) !== null) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $s. 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...
81
            $header .= '<var>'.$s.'</var> ';
82
        }
83
84 View Code Duplication
        if (($s = $o->getName()) !== 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...
85
            $header .= '<dfn>'.Kint_Object_Blob::escape($s).'</dfn> ';
86
87
            if ($s = $o->getOperator()) {
88
                $header .= Kint_Object_Blob::escape($s, 'ASCII').' ';
0 ignored issues
show
Documentation introduced by
'ASCII' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
            }
90
        }
91
92 View Code Duplication
        if (($s = $o->getType()) !== 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...
93
            $s = Kint_Object_Blob::escape($s);
94
95
            if ($o->reference) {
96
                $s = '&amp;'.$s;
97
            }
98
99
            $header .= '<var>'.$s.'</var> ';
100
        }
101
102 View Code Duplication
        if (($s = $o->getSize()) !== 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...
103
            $header .= '('.Kint_Object_Blob::escape($s).') ';
104
        }
105
106
        $header .= $content;
107
108
        if (!empty($ap)) {
109
            $header .= '<div class="access-path">'.Kint_Object_Blob::escape($ap).'</div>';
110
        }
111
112
        return $header.'</dt>';
113
    }
114
115
    abstract public function render($o);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
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...
116
}
117