Test Setup Failed
Push — test ( 528f91...abcbcc )
by Jonathan
03:20
created

RichRenderer   F

Complexity

Total Complexity 94

Size/Duplication

Total Lines 485
Duplicated Lines 23.71 %

Coupling/Cohesion

Components 4
Dependencies 5

Importance

Changes 0
Metric Value
dl 115
loc 485
rs 1.5789
c 0
b 0
f 0
wmc 94
lcom 4
cbo 5

14 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 31 5
A render() 0 13 3
C renderHeaderWrapper() 3 32 8
F renderHeader() 17 46 12
D renderChildren() 0 45 9
C renderTab() 0 41 16
A renderJs() 0 4 1
A renderCss() 8 8 2
A renderFolder() 0 8 2
D preRender() 34 34 9
C postRender() 8 62 15
B escape() 21 21 6
A getPlugin() 12 12 3
A ideLink() 12 12 3

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like RichRenderer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use RichRenderer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Kint\Renderer;
4
5
use Kint;
6
use Kint\Object\BasicObject;
7
use Kint\Object\BlobObject;
8
use Kint\Object\Representation\Representation;
9
10
class RichRenderer extends Renderer
11
{
12
    /**
13
     * RichRenderer object plugins should implement Kint\Renderer\Rich\ObjectPluginInterface.
14
     */
15
    public static $object_plugins = array(
0 ignored issues
show
Coding Style introduced by
$object_plugins 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...
16
        'blacklist' => 'Kint\\Renderer\\Rich\\BlacklistPlugin',
17
        'callable' => 'Kint\\Renderer\\Rich\\CallablePlugin',
18
        'closure' => 'Kint\\Renderer\\Rich\\ClosurePlugin',
19
        'color' => 'Kint\\Renderer\\Rich\\ColorPlugin',
20
        'depth_limit' => 'Kint\\Renderer\\Rich\\DepthLimitPlugin',
21
        'nothing' => 'Kint\\Renderer\\Rich\\NothingPlugin',
22
        'recursion' => 'Kint\\Renderer\\Rich\\RecursionPlugin',
23
        'simplexml_element' => 'Kint\\Renderer\\Rich\\SimpleXMLElementPlugin',
24
        'trace_frame' => 'Kint\\Renderer\\Rich\\TraceFramePlugin',
25
    );
26
27
    /**
28
     * RichRenderer tab plugins should implement Kint\Renderer\Rich\TabPluginInterface.
29
     */
30
    public static $tab_plugins = array(
0 ignored issues
show
Coding Style introduced by
$tab_plugins 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...
31
        'binary' => 'Kint\\Renderer\\Rich\\BinaryPlugin',
32
        'color' => 'Kint\\Renderer\\Rich\\ColorPlugin',
33
        'docstring' => 'Kint\\Renderer\\Rich\\DocstringPlugin',
34
        'microtime' => 'Kint\\Renderer\\Rich\\MicrotimePlugin',
35
        'source' => 'Kint\\Renderer\\Rich\\SourcePlugin',
36
        'table' => 'Kint\\Renderer\\Rich\\TablePlugin',
37
        'timestamp' => 'Kint\\Renderer\\Rich\\TimestampPlugin',
38
    );
39
40
    public static $pre_render_sources = array(
0 ignored issues
show
Coding Style introduced by
$pre_render_sources 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...
41
        'script' => array(
42
            array('Kint\\Renderer\\RichRenderer', 'renderJs'),
43
            array('Kint\\Renderer\\Rich\\MicrotimePlugin', 'renderJs'),
44
        ),
45
        'style' => array(
46
            array('Kint\\Renderer\\RichRenderer', 'renderCss'),
47
        ),
48
        'raw' => array(
49
            array('Kint\\Renderer\\RichRenderer', 'renderFolder'),
50
        ),
51
    );
52
53
    /**
54
     * Whether or not to render access paths.
55
     *
56
     * Access paths can become incredibly heavy with very deep and wide
57
     * structures. Given mostly public variables it will typically make
58
     * up one quarter of the output HTML size.
59
     *
60
     * If this is an unacceptably large amount and your browser is groaning
61
     * under the weight of the access paths - your first order of buisiness
62
     * should be to get a new browser. Failing that, use this to turn them off.
63
     *
64
     * @var bool
65
     */
66
    public static $access_paths = true;
0 ignored issues
show
Coding Style introduced by
$access_paths 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...
67
68
    /**
69
     * The maximum length of a string before it is truncated.
70
     *
71
     * Falsey to disable
72
     *
73
     * @var int
74
     */
75
    public static $strlen_max = 80;
0 ignored issues
show
Coding Style introduced by
$strlen_max 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...
76
77
    /**
78
     * Path to the CSS file to load by default.
79
     *
80
     * @var string
81
     */
82
    public static $theme = 'original.css';
83
84
    /**
85
     * Assume types and sizes don't need to be escaped.
86
     *
87
     * Turn this off if you use anything but ascii in your class names,
88
     * but it'll cause a slowdown of around 10%
89
     *
90
     * @var bool
91
     */
92
    public static $escape_types = false;
0 ignored issues
show
Coding Style introduced by
$escape_types 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...
93
94
    /**
95
     * Move all dumps to a folder at the bottom of the body.
96
     *
97
     * @var bool
98
     */
99
    public static $folder = true;
100
101
    protected static $been_run = false;
0 ignored issues
show
Coding Style introduced by
$been_run 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...
102
103
    protected $plugin_objs = array();
0 ignored issues
show
Coding Style introduced by
$plugin_objs 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...
104
    protected $mod_return = false;
0 ignored issues
show
Coding Style introduced by
$mod_return 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...
105
    protected $callee;
106
    protected $mini_trace;
0 ignored issues
show
Coding Style introduced by
$mini_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...
107
    protected $previous_caller;
0 ignored issues
show
Coding Style introduced by
$previous_caller 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...
108
    protected $file_link_format = false;
0 ignored issues
show
Coding Style introduced by
$file_link_format 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...
109
    protected $show_minitrace = true;
0 ignored issues
show
Coding Style introduced by
$show_minitrace 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...
110
    protected $auto_expand = false;
0 ignored issues
show
Coding Style introduced by
$auto_expand 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...
111
112
    public function __construct(array $params = array())
113
    {
114
        parent::__construct($params);
115
116
        $params += array(
117
            'modifiers' => array(),
118
            'minitrace' => array(),
119
            'callee' => null,
120
            'caller' => null,
121
        );
122
123
        $this->callee = $params['callee'];
124
        $this->mini_trace = $params['minitrace'];
125
        $this->previous_caller = $params['caller'];
126
127
        if (isset($params['settings']['return'])) {
128
            $this->mod_return = $params['settings']['return'];
129
        }
130
131
        if (isset($params['settings']['file_link_format'])) {
132
            $this->file_link_format = $params['settings']['file_link_format'];
133
        }
134
135
        if (empty($params['settings']['display_called_from'])) {
136
            $this->show_minitrace = false;
137
        }
138
139
        if (!empty($params['settings']['expanded'])) {
140
            $this->auto_expand = true;
141
        }
142
    }
143
144
    public function render(BasicObject $o)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

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...
145
    {
146
        if ($plugin = $this->getPlugin(self::$object_plugins, $o->hints)) {
147
            if (strlen($output = $plugin->renderObject($o))) {
148
                return $output;
149
            }
150
        }
151
152
        $children = $this->renderChildren($o);
153
        $header = $this->renderHeaderWrapper($o, (bool) strlen($children), $this->renderHeader($o));
154
155
        return '<dl>'.$header.$children.'</dl>';
156
    }
157
158
    public function renderHeaderWrapper(BasicObject $o, $has_children, $contents)
0 ignored issues
show
Coding Style introduced by
$has_children 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...
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...
159
    {
160
        $out = '<dt';
161
162
        if ($has_children) {
0 ignored issues
show
Coding Style introduced by
$has_children 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...
163
            $out .= ' class="kint-parent';
164
165
            if ($this->auto_expand) {
166
                $out .= ' kint-show';
167
            }
168
169
            $out .= '"';
170
        }
171
172
        $out .= '>';
173
174 View Code Duplication
        if (self::$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...
175
            $out .= '<span class="kint-access-path-trigger" title="Show access path">&rlarr;</span>';
176
        }
177
178
        if ($has_children) {
0 ignored issues
show
Coding Style introduced by
$has_children 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...
179
            $out .= '<span class="kint-popup-trigger" title="Open in new window">&rarr;</span><nav></nav>';
180
        }
181
182
        $out .= $contents;
183
184
        if (!empty($ap)) {
185
            $out .= '<div class="access-path">'.$this->escape($ap).'</div>';
186
        }
187
188
        return $out.'</dt>';
189
    }
190
191
    public function renderHeader(BasicObject $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...
192
    {
193
        $output = '';
194
195
        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...
196
            $output .= '<var>'.$s.'</var> ';
197
        }
198
199
        if (($s = $o->getName()) !== null) {
200
            $output .= '<dfn>'.$this->escape($s).'</dfn> ';
201
202
            if ($s = $o->getOperator()) {
203
                $output .= $this->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...
204
            }
205
        }
206
207 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...
208
            if (self::$escape_types) {
209
                $s = $this->escape($s);
210
            }
211
212
            if ($o->reference) {
213
                $s = '&amp;'.$s;
214
            }
215
216
            $output .= '<var>'.$s.'</var> ';
217
        }
218
219 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...
220
            if (self::$escape_types) {
221
                $s = $this->escape($s);
222
            }
223
            $output .= '('.$s.') ';
224
        }
225
226
        if (($s = $o->getValueShort()) !== null) {
227
            $s = preg_replace('/\s+/', ' ', $s);
228
229
            if (self::$strlen_max && BlobObject::strlen($s) > self::$strlen_max) {
230
                $s = substr($s, 0, self::$strlen_max).'...';
231
            }
232
            $output .= $this->escape($s);
233
        }
234
235
        return trim($output);
236
    }
237
238
    public function renderChildren(BasicObject $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...
239
    {
240
        $contents = array();
241
        $tabs = array();
242
243
        foreach ($o->getRepresentations() as $rep) {
244
            $result = $this->renderTab($o, $rep);
245
            if (strlen($result)) {
246
                $contents[] = $result;
247
                $tabs[] = $rep;
248
            }
249
        }
250
251
        if (empty($tabs)) {
252
            return '';
253
        }
254
255
        $output = '<dd>';
256
257
        if (count($tabs) === 1 && $tabs[0]->labelIsImplicit()) {
258
            $output .= reset($contents);
259
        } else {
260
            $output .= '<ul class="kint-tabs">';
261
262
            foreach ($tabs as $i => $tab) {
263
                if ($i === 0) {
264
                    $output .= '<li class="kint-active-tab">';
265
                } else {
266
                    $output .= '<li>';
267
                }
268
269
                $output .= $this->escape($tab->getLabel()).'</li>';
270
            }
271
272
            $output .= '</ul><ul>';
273
274
            foreach ($contents as $tab) {
275
                $output .= '<li>'.$tab.'</li>';
276
            }
277
278
            $output .= '</ul>';
279
        }
280
281
        return $output.'</dd>';
282
    }
283
284
    protected function renderTab(BasicObject $o, Representation $rep)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

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...
285
    {
286
        if ($plugin = $this->getPlugin(self::$tab_plugins, $rep->hints)) {
287
            if (strlen($output = $plugin->renderTab($rep))) {
288
                return $output;
289
            }
290
        }
291
292
        if (is_array($rep->contents)) {
293
            $output = '';
294
            foreach ($rep->contents as $obj) {
295
                $output .= $this->render($obj);
296
            }
297
298
            return $output;
299
        } elseif (is_string($rep->contents)) {
300
            $show_contents = false;
0 ignored issues
show
Coding Style introduced by
$show_contents 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...
301
302
            // If it is the value representation of a string and its whitespace
303
            // was truncated in the header, always display the full string
304
            if ($o->type !== 'string' || $o->value !== $rep) {
305
                $show_contents = true;
0 ignored issues
show
Coding Style introduced by
$show_contents 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...
306
            } elseif (preg_match('/(:?[\r\n\t\f\v]| {2})/', $rep->contents)) {
307
                $show_contents = true;
0 ignored issues
show
Coding Style introduced by
$show_contents 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...
308
            } elseif (self::$strlen_max && BlobObject::strlen($rep->contents) > self::$strlen_max) {
309
                $show_contents = true;
0 ignored issues
show
Coding Style introduced by
$show_contents 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...
310
            }
311
312
            if ($o->type === 'string' && $o->value === $rep && empty($o->encoding)) {
0 ignored issues
show
Bug introduced by
The property encoding does not seem to exist in Kint\Object\BasicObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
313
                $show_contents = false;
0 ignored issues
show
Coding Style introduced by
$show_contents 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...
314
            }
315
316
            if ($show_contents) {
0 ignored issues
show
Coding Style introduced by
$show_contents 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...
317
                return '<pre>'.$this->escape($rep->contents)."\n</pre>";
318
            }
319
        } elseif ($rep->contents instanceof BasicObject) {
320
            return $this->render($rep->contents);
321
        }
322
323
        return;
324
    }
325
326
    protected static function renderJs()
327
    {
328
        return file_get_contents(KINT_DIR.'/resources/compiled/rich.js');
329
    }
330
331 View Code Duplication
    protected static function renderCss()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
332
    {
333
        if (file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) {
334
            return file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme);
335
        } else {
336
            return file_get_contents(self::$theme);
337
        }
338
    }
339
340
    protected static function renderFolder()
341
    {
342
        if (self::$folder) {
343
            return '<div class="kint-rich kint-folder"><dl><dt class="kint-parent"><nav></nav>Kint</dt><dd class="kint-folder"></dd></dl></div>';
344
        } else {
345
            return '';
346
        }
347
    }
348
349 View Code Duplication
    public function preRender()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
350
    {
351
        $output = '';
352
353
        if (!self::$been_run || $this->mod_return) {
354
            foreach (self::$pre_render_sources as $type => $values) {
355
                $contents = '';
356
                foreach ($values as $v) {
357
                    $contents .= call_user_func($v, $this);
358
                }
359
360
                if (!strlen($contents)) {
361
                    continue;
362
                }
363
364
                switch ($type) {
365
                    case 'script':
366
                        $output .= '<script class="kint-script">'.$contents.'</script>';
367
                        break;
368
                    case 'style':
369
                        $output .= '<style class="kint-style">'.$contents.'</style>';
370
                        break;
371
                    default:
372
                        $output .= $contents;
373
                }
374
            }
375
376
            if (!$this->mod_return) {
377
                self::$been_run = true;
378
            }
379
        }
380
381
        return $output.'<div class="kint-rich">';
382
    }
383
384
    public function postRender()
385
    {
386
        if (!$this->show_minitrace) {
387
            return '</div>';
388
        }
389
390
        $output = '<footer>';
391
        $output .= '<span class="kint-popup-trigger" title="Open in new window">&rarr;</span> ';
392
393
        if (isset($this->callee['file'])) {
394
            if (!empty($this->mini_trace)) {
395
                $output .= '<nav></nav>';
396
            }
397
398
            $output .= 'Called from '.$this->ideLink($this->callee['file'], $this->callee['line']);
399
        }
400
401
        $caller = '';
402
403
        if (isset($this->previous_caller['class'])) {
404
            $caller .= $this->previous_caller['class'];
405
        }
406
        if (isset($this->previous_caller['type'])) {
407
            $caller .= $this->previous_caller['type'];
408
        }
409 View Code Duplication
        if (isset($this->previous_caller['function'])
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...
410
            && !in_array(
411
                $this->previous_caller['function'],
412
                array('include', 'include_once', 'require', 'require_once')
413
            )
414
        ) {
415
            $caller .= $this->previous_caller['function'].'()';
416
        }
417
418
        if ($caller) {
419
            $output .= ' ['.$caller.']';
420
        }
421
422
        if (!empty($this->mini_trace)) {
423
            $output .= '<ol>';
424
            foreach ($this->mini_trace as $step) {
425
                $output .= '<li>'.$this->ideLink($step['file'], $step['line']); // closing tag not required
426
                if (isset($step['function'])
427
                    && !in_array($step['function'], array('include', 'include_once', 'require', 'require_once'))
428
                ) {
429
                    $output .= ' [';
430
                    if (isset($step['class'])) {
431
                        $output .= $step['class'];
432
                    }
433
                    if (isset($step['type'])) {
434
                        $output .= $step['type'];
435
                    }
436
                    $output .= $step['function'].'()]';
437
                }
438
            }
439
            $output .= '</ol>';
440
        }
441
442
        $output .= '</footer></div>';
443
444
        return $output;
445
    }
446
447 View Code Duplication
    public function escape($string, $encoding = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
448
    {
449
        if ($encoding === false) {
450
            $encoding = BlobObject::detectEncoding($string);
451
        }
452
453
        $original_encoding = $encoding;
0 ignored issues
show
Coding Style introduced by
$original_encoding 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...
454
455
        if ($encoding === false || $encoding === 'ASCII') {
456
            $encoding = 'UTF-8';
457
        }
458
459
        $string = htmlspecialchars($string, ENT_NOQUOTES, $encoding);
460
461
        // this call converts all non-ASCII characters into numeirc htmlentities
462
        if (extension_loaded('mbstring') && $original_encoding !== 'ASCII') {
0 ignored issues
show
Coding Style introduced by
$original_encoding 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...
463
            $string = mb_encode_numericentity($string, array(0x80, 0xffff, 0, 0xffff), $encoding);
464
        }
465
466
        return $string;
467
    }
468
469 View Code Duplication
    protected function getPlugin(array $plugins, array $hints)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
470
    {
471
        if ($plugins = $this->matchPlugins($plugins, $hints)) {
472
            $plugin = end($plugins);
473
474
            if (!isset($this->plugin_objs[$plugin])) {
475
                $this->plugin_objs[$plugin] = new $plugin($this);
476
            }
477
478
            return $this->plugin_objs[$plugin];
479
        }
480
    }
481
482 View Code Duplication
    protected function ideLink($file, $line)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
483
    {
484
        $shortenedPath = $this->escape(Kint::shortenPath($file));
485
        if (!$this->file_link_format) {
486
            return $shortenedPath.':'.$line;
487
        }
488
489
        $ideLink = Kint::getIdeLink($file, $line);
490
        $class = (strpos($ideLink, 'http://') === 0) ? 'class="kint-ide-link" ' : '';
491
492
        return "<a {$class}href=\"{$ideLink}\">{$shortenedPath}:{$line}</a>";
493
    }
494
}
495