Test Setup Failed
Push — test ( dd7d7c...b3915a )
by Jonathan
03:06
created

RichRenderer::renderJs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Renderer;
4
5
use Kint\Kint;
6
use Kint\Object\BasicObject;
7
use Kint\Object\BlobObject;
8
use Kint\Object\InstanceObject;
9
use Kint\Object\Representation\Representation;
10
11
class RichRenderer extends Renderer
0 ignored issues
show
Coding Style introduced by
The property $object_plugins is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $tab_plugins is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $pre_render_sources is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $access_paths is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $strlen_max is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $escape_types is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $been_run is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $plugin_objs is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
12
{
13
    /**
14
     * RichRenderer object plugins should implement Kint\Renderer\Rich\ObjectPluginInterface.
15
     */
16
    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...
17
        'blacklist' => 'Kint\\Renderer\\Rich\\BlacklistPlugin',
18
        'callable' => 'Kint\\Renderer\\Rich\\CallablePlugin',
19
        'closure' => 'Kint\\Renderer\\Rich\\ClosurePlugin',
20
        'color' => 'Kint\\Renderer\\Rich\\ColorPlugin',
21
        'depth_limit' => 'Kint\\Renderer\\Rich\\DepthLimitPlugin',
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
    /**
102
     * Sort mode for object properties.
103
     *
104
     * @var int
105
     */
106
    public static $sort = self::SORT_NONE;
107
108
    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...
109
110
    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...
111
112
    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...
113
    {
114
        if ($plugin = $this->getPlugin(self::$object_plugins, $o->hints)) {
115
            if (strlen($output = $plugin->renderObject($o))) {
116
                return $output;
117
            }
118
        }
119
120
        $children = $this->renderChildren($o);
121
        $header = $this->renderHeaderWrapper($o, (bool) strlen($children), $this->renderHeader($o));
122
123
        return '<dl>'.$header.$children.'</dl>';
124
    }
125
126
    public function renderNothing()
127
    {
128
        return '<dl><dt><var>No argument</var></dt></dl>';
129
    }
130
131
    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...
Coding Style Naming introduced by
The parameter $has_children is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
132
    {
133
        $out = '<dt';
134
135
        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...
136
            $out .= ' class="kint-parent';
137
138
            if ($this->expand) {
139
                $out .= ' kint-show';
140
            }
141
142
            $out .= '"';
143
        }
144
145
        $out .= '>';
146
147 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...
148
            $out .= '<span class="kint-access-path-trigger" title="Show access path">&rlarr;</span>';
149
        }
150
151
        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...
152
            $out .= '<span class="kint-popup-trigger" title="Open in new window">&boxbox;</span><nav></nav>';
153
        }
154
155
        $out .= $contents;
156
157
        if (!empty($ap)) {
158
            $out .= '<div class="access-path">'.$this->escape($ap).'</div>';
159
        }
160
161
        return $out.'</dt>';
162
    }
163
164
    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...
165
    {
166
        $output = '';
167
168
        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...
169
            $output .= '<var>'.$s.'</var> ';
170
        }
171
172
        if (($s = $o->getName()) !== null) {
173
            $output .= '<dfn>'.$this->escape($s).'</dfn> ';
174
175
            if ($s = $o->getOperator()) {
176
                $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...
177
            }
178
        }
179
180 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...
181
            if (self::$escape_types) {
182
                $s = $this->escape($s);
183
            }
184
185
            if ($o->reference) {
186
                $s = '&amp;'.$s;
187
            }
188
189
            $output .= '<var>'.$s.'</var> ';
190
        }
191
192 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...
193
            if (self::$escape_types) {
194
                $s = $this->escape($s);
195
            }
196
            $output .= '('.$s.') ';
197
        }
198
199
        if (($s = $o->getValueShort()) !== null) {
200
            $s = preg_replace('/\s+/', ' ', $s);
201
202
            if (self::$strlen_max && BlobObject::strlen($s) > self::$strlen_max) {
203
                $s = substr($s, 0, self::$strlen_max).'...';
204
            }
205
            $output .= $this->escape($s);
206
        }
207
208
        return trim($output);
209
    }
210
211
    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...
212
    {
213
        $contents = array();
214
        $tabs = array();
215
216
        foreach ($o->getRepresentations() as $rep) {
217
            $result = $this->renderTab($o, $rep);
218
            if (strlen($result)) {
219
                $contents[] = $result;
220
                $tabs[] = $rep;
221
            }
222
        }
223
224
        if (empty($tabs)) {
225
            return '';
226
        }
227
228
        $output = '<dd>';
229
230
        if (count($tabs) === 1 && $tabs[0]->labelIsImplicit()) {
231
            $output .= reset($contents);
232
        } else {
233
            $output .= '<ul class="kint-tabs">';
234
235
            foreach ($tabs as $i => $tab) {
236
                if ($i === 0) {
237
                    $output .= '<li class="kint-active-tab">';
238
                } else {
239
                    $output .= '<li>';
240
                }
241
242
                $output .= $this->escape($tab->getLabel()).'</li>';
243
            }
244
245
            $output .= '</ul><ul>';
246
247
            foreach ($contents as $tab) {
248
                $output .= '<li>'.$tab.'</li>';
249
            }
250
251
            $output .= '</ul>';
252
        }
253
254
        return $output.'</dd>';
255
    }
256
257
    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...
258
    {
259
        if ($plugin = $this->getPlugin(self::$tab_plugins, $rep->hints)) {
260
            if (strlen($output = $plugin->renderTab($rep))) {
261
                return $output;
262
            }
263
        }
264
265
        if (is_array($rep->contents)) {
266
            $output = '';
267
268 View Code Duplication
            if ($o instanceof InstanceObject && $rep->getName() === 'properties') {
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...
269
                foreach (self::sortProperties($rep->contents, self::$sort) as $obj) {
270
                    $output .= $this->render($obj);
271
                }
272
            } else {
273
                foreach ($rep->contents as $obj) {
274
                    $output .= $this->render($obj);
275
                }
276
            }
277
278
            return $output;
279
        } elseif (is_string($rep->contents)) {
280
            $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...
281
282
            // If it is the value representation of a string and its whitespace
283
            // was truncated in the header, always display the full string
284
            if ($o->type !== 'string' || $o->value !== $rep) {
285
                $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...
286
            } else {
287
                if (preg_match('/(:?[\r\n\t\f\v]| {2})/', $rep->contents)) {
288
                    $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...
289
                } elseif (self::$strlen_max && BlobObject::strlen($o->getValueShort()) > self::$strlen_max) {
290
                    $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...
291
                }
292
293
                if (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...
294
                    $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...
295
                }
296
            }
297
298
            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...
299
                return '<pre>'.$this->escape($rep->contents)."\n</pre>";
300
            }
301
        } elseif ($rep->contents instanceof BasicObject) {
302
            return $this->render($rep->contents);
303
        }
304
305
        return;
306
    }
307
308
    protected static function renderJs()
309
    {
310
        return file_get_contents(KINT_DIR.'/resources/compiled/rich.js');
311
    }
312
313 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...
314
    {
315
        if (file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) {
316
            return file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme);
317
        } else {
318
            return file_get_contents(self::$theme);
319
        }
320
    }
321
322
    protected static function renderFolder()
323
    {
324
        if (self::$folder) {
325
            return '<div class="kint-rich kint-folder"><dl><dt class="kint-parent"><nav></nav>Kint</dt><dd class="kint-folder"></dd></dl></div>';
326
        } else {
327
            return '';
328
        }
329
    }
330
331 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...
332
    {
333
        $output = '';
334
335
        if (!self::$been_run || $this->return_mode) {
336
            foreach (self::$pre_render_sources as $type => $values) {
337
                $contents = '';
338
                foreach ($values as $v) {
339
                    $contents .= call_user_func($v, $this);
340
                }
341
342
                if (!strlen($contents)) {
343
                    continue;
344
                }
345
346
                switch ($type) {
347
                    case 'script':
348
                        $output .= '<script class="kint-script">'.$contents.'</script>';
349
                        break;
350
                    case 'style':
351
                        $output .= '<style class="kint-style">'.$contents.'</style>';
352
                        break;
353
                    default:
354
                        $output .= $contents;
355
                }
356
            }
357
358
            if (!$this->return_mode) {
359
                self::$been_run = true;
360
            }
361
        }
362
363
        return $output.'<div class="kint-rich">';
364
    }
365
366
    public function postRender()
367
    {
368
        if (!$this->show_trace) {
369
            return '</div>';
370
        }
371
372
        $output = '<footer>';
373
        $output .= '<span class="kint-popup-trigger" title="Open in new window">&boxbox;</span> ';
374
375
        if (isset($this->call_info['callee']['file'])) {
376
            if (!empty($this->call_info['trace']) && count($this->call_info['trace']) > 1) {
377
                $output .= '<nav></nav>';
378
            }
379
380
            $output .= 'Called from '.$this->ideLink(
381
                $this->call_info['callee']['file'],
382
                $this->call_info['callee']['line']
383
            );
384
        }
385
386 View Code Duplication
        if (isset($this->call_info['callee']['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...
387
                !empty($this->call_info['callee']['class']) ||
388
                !in_array(
389
                    $this->call_info['callee']['function'],
390
                    array('include', 'include_once', 'require', 'require_once')
391
                )
392
            )
393
        ) {
394
            $output .= ' [';
395
            if (isset($this->call_info['callee']['class'])) {
396
                $output .= $this->call_info['callee']['class'];
397
            }
398
            if (isset($this->call_info['callee']['type'])) {
399
                $output .= $this->call_info['callee']['type'];
400
            }
401
            $output .= $this->call_info['callee']['function'].'()]';
402
        }
403
404
        if (!empty($this->call_info['trace']) && count($this->call_info['trace']) > 1) {
405
            $output .= '<ol>';
406
            foreach ($this->call_info['trace'] as $index => $step) {
407
                if (!$index) {
408
                    continue;
409
                }
410
411
                $output .= '<li>'.$this->ideLink($step['file'], $step['line']); // closing tag not required
412
                if (isset($step['function'])
413
                    && !in_array($step['function'], array('include', 'include_once', 'require', 'require_once'))
414
                ) {
415
                    $output .= ' [';
416
                    if (isset($step['class'])) {
417
                        $output .= $step['class'];
418
                    }
419
                    if (isset($step['type'])) {
420
                        $output .= $step['type'];
421
                    }
422
                    $output .= $step['function'].'()]';
423
                }
424
            }
425
            $output .= '</ol>';
426
        }
427
428
        $output .= '</footer></div>';
429
430
        return $output;
431
    }
432
433 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...
434
    {
435
        if ($encoding === false) {
436
            $encoding = BlobObject::detectEncoding($string);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $encoding. This often makes code more readable.
Loading history...
437
        }
438
439
        $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...
440
441
        if ($encoding === false || $encoding === 'ASCII') {
442
            $encoding = 'UTF-8';
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $encoding. This often makes code more readable.
Loading history...
443
        }
444
445
        $string = htmlspecialchars($string, ENT_NOQUOTES, $encoding);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $string. This often makes code more readable.
Loading history...
446
447
        // this call converts all non-ASCII characters into numeirc htmlentities
448
        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...
449
            $string = mb_encode_numericentity($string, array(0x80, 0xffff, 0, 0xffff), $encoding);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $string. This often makes code more readable.
Loading history...
450
        }
451
452
        return $string;
453
    }
454
455 View Code Duplication
    protected function getPlugin(array $plugins, array $hints)
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...
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...
456
    {
457
        if ($plugins = $this->matchPlugins($plugins, $hints)) {
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $plugins. This often makes code more readable.
Loading history...
458
            $plugin = end($plugins);
459
460
            if (!isset($this->plugin_objs[$plugin])) {
461
                $this->plugin_objs[$plugin] = new $plugin($this);
462
            }
463
464
            return $this->plugin_objs[$plugin];
465
        }
466
    }
467
468 View Code Duplication
    public 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...
469
    {
470
        $path = $this->escape(Kint::shortenPath($file)).':'.$line;
471
        $ideLink = Kint::getIdeLink($file, $line);
472
473
        if (!$ideLink) {
474
            return $path;
475
        }
476
477
        $class = '';
478
479
        if (preg_match($ideLink, '/https?:\/\//i')) {
480
            $class = 'class="kint-ide-link" ';
481
        }
482
483
        return '<a '.$class.'href="'.$this->escape($ideLink).'">'.$path.'</a>';
484
    }
485
}
486