Test Setup Failed
Push — test ( 089b88...0e81d9 )
by Jonathan
04:36
created

Kint   C

Complexity

Total Complexity 77

Size/Duplication

Total Lines 573
Duplicated Lines 3.84 %

Coupling/Cohesion

Components 3
Dependencies 5

Importance

Changes 0
Metric Value
dl 22
loc 573
rs 5.4715
c 0
b 0
f 0
wmc 77
lcom 3
cbo 5

7 Methods

Rating   Name   Duplication   Size   Complexity  
B settings() 0 33 4
B trace() 0 25 4
A dumpArray() 0 12 1
F dump() 13 160 37
D shortenPath() 0 37 10
A getIdeLink() 0 4 1
F getCalleeInfo() 9 97 20

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 Kint 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 Kint, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Kint;
4
5
use Kint\Object\BasicObject;
6
use Kint\Object\NothingObject;
7
use Kint\Parser\Parser;
8
use Kint\Parser\Plugin;
9
use Kint\Parser\TracePlugin;
10
11
class Kint
0 ignored issues
show
Coding Style introduced by
Kint does not seem to conform to the naming convention (Utils?$).

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
The property $enabled_mode 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 $mode_default 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 $mode_default_cli 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 $file_link_format 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 $display_called_from 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 $app_root_dirs 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 $max_depth 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 $cli_detection 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_pool 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 $dump_array 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
     * @var mixed Kint mode
15
     *
16
     * false: Disabled
17
     * true: Enabled, default mode selection
18
     * other: Manual mode selection
19
     */
20
    public static $enabled_mode = true;
0 ignored issues
show
Coding Style introduced by
$enabled_mode 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...
21
22
    /**
23
     * Default mode.
24
     *
25
     * @var string
26
     */
27
    public static $mode_default = self::MODE_RICH;
0 ignored issues
show
Coding Style introduced by
$mode_default 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...
28
29
    /**
30
     * Default mode in CLI with cli_detection on.
31
     *
32
     * @var string
33
     */
34
    public static $mode_default_cli = self::MODE_CLI;
0 ignored issues
show
Coding Style introduced by
$mode_default_cli 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...
35
36
    /**
37
     * @var bool Return output instead of echoing
38
     */
39
    public static $return;
40
41
    /**
42
     * @var string format of the link to the source file in trace entries.
43
     *
44
     * Use %f for file path, %l for line number.
45
     *
46
     * [!] EXAMPLE (works with for phpStorm and RemoteCall Plugin):
47
     *
48
     * Kint::$file_link_format = 'http://localhost:8091/?message=%f:%l';
49
     */
50
    public static $file_link_format = '';
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...
51
52
    /**
53
     * @var bool whether to display where kint was called from
54
     */
55
    public static $display_called_from = true;
0 ignored issues
show
Coding Style introduced by
$display_called_from 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...
56
57
    /**
58
     * @var array base directories of your application that will be displayed instead of the full path.
59
     *
60
     * Keys are paths, values are replacement strings
61
     *
62
     * [!] EXAMPLE (for Laravel 5):
63
     *
64
     * Kint::$app_root_dirs = [
65
     *     base_path() => '<BASE>',
66
     *     app_path() => '<APP>',
67
     *     config_path() => '<CONFIG>',
68
     *     database_path() => '<DATABASE>',
69
     *     public_path() => '<PUBLIC>',
70
     *     resource_path() => '<RESOURCE>',
71
     *     storage_path() => '<STORAGE>',
72
     * ];
73
     *
74
     * Defaults to [$_SERVER['DOCUMENT_ROOT'] => '<ROOT>']
75
     */
76
    public static $app_root_dirs = array();
0 ignored issues
show
Coding Style introduced by
$app_root_dirs 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...
77
78
    /**
79
     * @var int max array/object levels to go deep, if zero no limits are applied
80
     */
81
    public static $max_depth = 6;
0 ignored issues
show
Coding Style introduced by
$max_depth 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...
82
83
    /**
84
     * @var bool expand all trees by default for rich view
85
     */
86
    public static $expanded = false;
87
88
    /**
89
     * @var bool enable detection when Kint is command line.
90
     *
91
     * Formats output with whitespace only; does not HTML-escape it
92
     */
93
    public static $cli_detection = true;
0 ignored issues
show
Coding Style introduced by
$cli_detection 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...
94
95
    /**
96
     * @var array Kint aliases. Add debug functions in Kint wrappers here to fix modifiers and backtraces
97
     */
98
    public static $aliases = array(
99
        array('Kint\\Kint', 'dump'),
100
        array('Kint\\Kint', 'trace'),
101
        array('Kint\\Kint', 'dumpArray'),
102
    );
103
104
    /**
105
     * @var array Kint\Renderer\Renderer descendants. Add to array to extend.
106
     */
107
    public static $renderers = array(
108
        self::MODE_RICH => 'Kint\\Renderer\\RichRenderer',
109
        self::MODE_PLAIN => 'Kint\\Renderer\\PlainRenderer',
110
        self::MODE_TEXT => 'Kint\\Renderer\\TextRenderer',
111
        self::MODE_CLI => 'Kint\\Renderer\\CliRenderer',
112
    );
113
114
    const MODE_RICH = 'r';
115
    const MODE_TEXT = 't';
116
    const MODE_CLI = 'c';
117
    const MODE_PLAIN = 'p';
118
119
    public static $plugins = array(
120
        'Kint\\Parser\\ArrayObjectPlugin',
121
        'Kint\\Parser\\Base64Plugin',
122
        'Kint\\Parser\\BlacklistPlugin',
123
        'Kint\\Parser\\ClassMethodsPlugin',
124
        'Kint\\Parser\\ClassStaticsPlugin',
125
        'Kint\\Parser\\ClosurePlugin',
126
        'Kint\\Parser\\ColorPlugin',
127
        'Kint\\Parser\\DateTimePlugin',
128
        'Kint\\Parser\\FsPathPlugin',
129
        'Kint\\Parser\\IteratorPlugin',
130
        'Kint\\Parser\\JsonPlugin',
131
        'Kint\\Parser\\MicrotimePlugin',
132
        'Kint\\Parser\\SimpleXMLElementPlugin',
133
        'Kint\\Parser\\SplFileInfoPlugin',
134
        'Kint\\Parser\\SplObjectStoragePlugin',
135
        'Kint\\Parser\\StreamPlugin',
136
        'Kint\\Parser\\TablePlugin',
137
        'Kint\\Parser\\ThrowablePlugin',
138
        'Kint\\Parser\\TimestampPlugin',
139
        'Kint\\Parser\\ToStringPlugin',
140
        'Kint\\Parser\\TracePlugin',
141
        'Kint\\Parser\\XmlPlugin',
142
    );
143
144
    private static $plugin_pool = array();
0 ignored issues
show
Coding Style introduced by
$plugin_pool 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...
145
    private static $dump_array = false;
0 ignored issues
show
Coding Style introduced by
$dump_array 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...
146
    private static $names = array();
147
148
    /**
149
     * Stashes or sets all settings at once.
150
     *
151
     * @param array|null $settings Array of all settings to be set or null to set none
152
     *
153
     * @return array Current settings
154
     */
155
    public static function settings(array $settings = null)
156
    {
157
        static $keys = array(
158
            'aliases',
159
            'app_root_dirs',
160
            'cli_detection',
161
            'display_called_from',
162
            'enabled_mode',
163
            'expanded',
164
            'file_link_format',
165
            'max_depth',
166
            'mode_default',
167
            'mode_default_cli',
168
            'renderers',
169
            'return',
170
            'plugins',
171
        );
172
173
        $out = array();
174
175
        foreach ($keys as $key) {
176
            $out[$key] = self::$$key;
177
        }
178
179
        if ($settings !== null) {
180
            $in = array_intersect_key($settings, $out);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $in. 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...
181
            foreach ($in as $key => $val) {
182
                self::$$key = $val;
183
            }
184
        }
185
186
        return $out;
187
    }
188
189
    /**
190
     * Prints a debug backtrace, same as Kint::dump(1).
191
     *
192
     * @param array $trace [OPTIONAL] you can pass your own trace, otherwise, `debug_backtrace` will be called
0 ignored issues
show
Documentation introduced by
Should the type for parameter $trace not be null|array? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
193
     *
194
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
195
     */
196
    public static function trace(array $trace = null)
197
    {
198
        if ($trace === null) {
199
            $trace = debug_backtrace(true);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $trace. This often makes code more readable.
Loading history...
200
        } else {
201
            return self::dump($trace);
202
        }
203
204
        TracePlugin::normalizeAliases(self::$aliases);
205
206
        $trimmed_trace = array();
0 ignored issues
show
Coding Style introduced by
$trimmed_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...
207
208
        foreach ($trace as $frame) {
209
            if (TracePlugin::frameIsListed($frame, self::$aliases)) {
210
                $trimmed_trace = array();
0 ignored issues
show
Coding Style introduced by
$trimmed_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...
211
            }
212
213
            $trimmed_trace[] = $frame;
0 ignored issues
show
Coding Style introduced by
$trimmed_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...
214
        }
215
216
        return self::dumpArray(
217
            array($trimmed_trace),
0 ignored issues
show
Coding Style introduced by
$trimmed_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...
218
            array(BasicObject::blank('Kint\\Kint::trace()', 'debug_backtrace()'))
219
        );
220
    }
221
222
    /**
223
     * Dumps an array as separate values, and uses $names to seed the parser.
224
     *
225
     * @param array              $data  Data to be dumped
226
     * @param BasicObject[]|null $names Array of BasicObject to seed the parser with
227
     */
228
    public static function dumpArray(array $data, array $names = null)
229
    {
230
        self::$names = $names;
0 ignored issues
show
Documentation Bug introduced by
It seems like $names can be null. However, the property $names is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
231
        self::$dump_array = true;
232
233
        $out = self::dump($data);
234
235
        self::$names = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $names.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
236
        self::$dump_array = false;
237
238
        return $out;
239
    }
240
241
    /**
242
     * Dump information about variables, accepts any number of parameters, supports modifiers:.
243
     *
244
     *  clean up any output before kint and place the dump at the top of page:
245
     *   - Kint::dump()
246
     *  *****
247
     *  expand all nodes on display:
248
     *   ! Kint::dump()
249
     *  *****
250
     *  dump variables disregarding their depth:
251
     *   + Kint::dump()
252
     *  *****
253
     *  return output instead of displaying it:
254
     *
255
     *   @ Kint::dump()
256
     *  *****
257
     *  force output as plain text
258
     *   ~ Kint::dump()
259
     *
260
     * Modifiers are supported by all dump wrapper functions, including Kint::trace(). Space is optional.
261
     *
262
     * @param mixed $data
263
     *
264
     * @return int|string
265
     */
266
    public static function dump($data = null)
267
    {
268
        if (!self::$enabled_mode) {
269
            return 0;
270
        }
271
272
        $stash = self::settings();
273
        $num_args = func_num_args();
0 ignored issues
show
Coding Style introduced by
$num_args 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...
274
275
        list($params, $modifiers, $callee, $caller, $minitrace) = self::getCalleeInfo(
276
            debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),
277
            $num_args
0 ignored issues
show
Coding Style introduced by
$num_args 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...
278
        );
279
280
        // set mode for current run
281 View Code Duplication
        if (self::$enabled_mode === true) {
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...
282
            self::$enabled_mode = self::$mode_default;
283
            if (PHP_SAPI === 'cli' && self::$cli_detection === true) {
284
                self::$enabled_mode = self::$mode_default_cli;
285
            }
286
        }
287
288
        if (in_array('~', $modifiers)) {
289
            self::$enabled_mode = self::MODE_TEXT;
290
        }
291
292
        if (!array_key_exists(self::$enabled_mode, self::$renderers)) {
293
            $renderer = self::$renderers[self::MODE_PLAIN];
294
        } else {
295
            $renderer = self::$renderers[self::$enabled_mode];
296
        }
297
298
        // process modifiers: @, +, ! and -
299
        if (in_array('-', $modifiers)) {
300
            while (ob_get_level()) {
301
                ob_end_clean();
302
            }
303
        }
304
        if (in_array('!', $modifiers)) {
305
            self::$expanded = true;
306
        }
307
        if (in_array('+', $modifiers)) {
308
            self::$max_depth = 0;
309
        }
310
        if (in_array('@', $modifiers)) {
311
            self::$return = true;
312
        }
313
314
        $renderer = new $renderer(array(
315
            'num_args' => $num_args,
0 ignored issues
show
Coding Style introduced by
$num_args 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...
316
            'params' => $params,
317
            'modifiers' => $modifiers,
318
            'callee' => $callee,
319
            'caller' => $caller,
320
            'minitrace' => $minitrace,
321
            'settings' => self::settings(),
322
            'stash' => $stash,
323
        ));
324
325
        $plugins = array();
326
327
        foreach (self::$plugins as $plugin) {
328
            if ($plugin instanceof Plugin) {
329
                $plugins[] = $plugin;
330
            } elseif (is_string($plugin) && is_subclass_of($plugin, 'Kint\\Parser\\Plugin')) {
331
                if (!isset(self::$plugin_pool[$plugin])) {
332
                    $p = new $plugin();
333
                    self::$plugin_pool[$plugin] = $p;
334
                }
335
                $plugins[] = self::$plugin_pool[$plugin];
336
            }
337
        }
338
339
        $plugins = $renderer->parserPlugins($plugins);
340
341
        $output = $renderer->preRender();
342
343
        $parser = new Parser(self::$max_depth, empty($caller['class']) ? null : $caller['class']);
344
345
        foreach ($plugins as $plugin) {
346
            $parser->addPlugin($plugin);
347
        }
348
349
        // Kint::dump(1) shorthand
350
        if (!self::$dump_array && (!isset($params[0]['name']) || $params[0]['name'] == '1') && $num_args === 1 && $data === 1) {
0 ignored issues
show
Coding Style introduced by
$num_args 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...
351
            $data = debug_backtrace(true);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $data. This often makes code more readable.
Loading history...
352
            $trace = array();
353
354
            // No need to normalize as we've already called it through getCalleeInfo at this point
355 View Code Duplication
            foreach ($data as $index => $frame) {
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...
356
                if (TracePlugin::frameIsListed($frame, self::$aliases)) {
357
                    $trace = array();
358
                }
359
360
                $trace[] = $frame;
361
            }
362
363
            $lastframe = reset($trace);
364
            $tracename = $lastframe['function'].'(1)';
365
            if (isset($lastframe['class'], $lastframe['type'])) {
366
                $tracename = $lastframe['class'].$lastframe['type'].$tracename;
367
            }
368
            $tracebase = BasicObject::blank($tracename, 'debug_backtrace()');
369
370
            $output .= $renderer->render($parser->parse($trace, $tracebase));
371
        } else {
372
            $data = func_get_args();
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $data. This often makes code more readable.
Loading history...
373
            if ($data === array()) {
374
                $output .= $renderer->render(new NothingObject());
375
            }
376
377
            if (self::$dump_array) {
378
                $data = $data[0];
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $data. This often makes code more readable.
Loading history...
379
            }
380
381
            static $blacklist = array('null', 'true', 'false', 'array(...)', 'array()', '"..."', 'b"..."', '[...]', '[]', '(...)', '()');
382
383
            foreach ($data as $i => $argument) {
384
                if (isset(self::$names[$i])) {
385
                    $output .= $renderer->render(
386
                        $parser->parse($argument, self::$names[$i])
387
                    );
388
                    continue;
389
                }
390
391
                if (!isset($params[$i]['name']) || is_numeric($params[$i]['name']) || in_array(str_replace("'", '"', strtolower($params[$i]['name'])), $blacklist, true)) {
392
                    $name = null;
393
                } else {
394
                    $name = $params[$i]['name'];
395
                }
396
397
                if (isset($params[$i]['path'])) {
398
                    $access_path = $params[$i]['path'];
0 ignored issues
show
Coding Style introduced by
$access_path 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...
399
400
                    if (!empty($params[$i]['expression'])) {
401
                        $access_path = '('.$access_path.')';
0 ignored issues
show
Coding Style introduced by
$access_path 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...
402
                    }
403
                } else {
404
                    $access_path = '$'.$i;
0 ignored issues
show
Coding Style introduced by
$access_path 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...
405
                }
406
407
                $output .= $renderer->render(
408
                    $parser->parse($argument, BasicObject::blank($name, $access_path))
0 ignored issues
show
Coding Style introduced by
$access_path 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...
409
                );
410
            }
411
        }
412
413
        $output .= $renderer->postRender();
414
415
        if (self::$return) {
416
            self::settings($stash);
417
418
            return $output;
419
        }
420
421
        self::settings($stash);
422
        echo $output;
423
424
        return 0;
425
    }
426
427
    /**
428
     * generic path display callback, can be configured in app_root_dirs; purpose is
429
     * to show relevant path info and hide as much of the path as possible.
430
     *
431
     * @param string $file
432
     *
433
     * @return string
434
     */
435
    public static function shortenPath($file)
436
    {
437
        $file = array_values(array_filter(explode('/', str_replace('\\', '/', $file)), 'strlen'));
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $file. This often makes code more readable.
Loading history...
438
439
        $longest_match = 0;
0 ignored issues
show
Coding Style introduced by
$longest_match 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
        $match = '/';
441
442
        foreach (self::$app_root_dirs as $path => $alias) {
443
            if (empty($path)) {
444
                continue;
445
            }
446
447
            $path = array_values(array_filter(explode('/', str_replace('\\', '/', $path)), 'strlen'));
448
449
            if (array_slice($file, 0, count($path)) === $path && count($path) > $longest_match) {
0 ignored issues
show
Coding Style introduced by
$longest_match 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...
450
                $longest_match = count($path);
0 ignored issues
show
Coding Style introduced by
$longest_match 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...
451
                $match = $alias;
452
            }
453
        }
454
455
        if ($longest_match) {
0 ignored issues
show
Coding Style introduced by
$longest_match 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...
456
            $file = array_merge(array($match), array_slice($file, $longest_match));
0 ignored issues
show
Coding Style introduced by
$longest_match 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
Consider using a different name than the parameter $file. This often makes code more readable.
Loading history...
457
458
            return implode('/', $file);
459
        } else {
460
            // fallback to find common path with Kint dir
461
            $kint = array_values(array_filter(explode('/', str_replace('\\', '/', KINT_DIR)), 'strlen'));
462
463
            foreach ($file as $i => $part) {
464
                if (!isset($kint[$i]) || $kint[$i] !== $part) {
465
                    return ($i ? '.../' : '/').implode('/', array_slice($file, $i));
466
                }
467
            }
468
469
            return '/'.implode('/', $file);
470
        }
471
    }
472
473
    public static function getIdeLink($file, $line)
474
    {
475
        return str_replace(array('%f', '%l'), array($file, $line), self::$file_link_format);
476
    }
477
478
    /**
479
     * returns parameter names that the function was passed, as well as any predefined symbols before function
480
     * call (modifiers).
481
     *
482
     * @param array $trace
483
     *
484
     * @return array($params, $modifiers, $callee, $caller, $miniTrace)
0 ignored issues
show
Documentation introduced by
The doc-type array($params, could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
485
     */
486
    private static function getCalleeInfo($trace, $num_params)
0 ignored issues
show
Coding Style introduced by
$num_params 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 Naming introduced by
The parameter $num_params 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...
487
    {
488
        TracePlugin::normalizeAliases(self::$aliases);
489
        $miniTrace = array();
490
491 View Code Duplication
        foreach ($trace as $index => $frame) {
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...
492
            if (TracePlugin::frameIsListed($frame, self::$aliases)) {
493
                $miniTrace = array();
494
            }
495
496
            if (!TracePlugin::frameIsListed($frame, array('spl_autoload_call'))) {
497
                $miniTrace[] = $frame;
498
            }
499
        }
500
501
        $callee = reset($miniTrace);
502
        $caller = next($miniTrace);
503
        if (!$callee) {
504
            $callee = null;
505
        }
506
        if (!$caller) {
507
            $caller = null;
508
        }
509
510
        unset($miniTrace[0]);
511
512
        foreach ($miniTrace as $index => &$frame) {
513
            if (!isset($frame['file'], $frame['line'])) {
514
                unset($miniTrace[$index]);
515
            } else {
516
                unset($frame['object'], $frame['args']);
517
            }
518
        }
519
520
        $miniTrace = array_values($miniTrace);
521
522
        if (!isset($callee['file'], $callee['line']) || !is_readable($callee['file'])) {
523
            return array(null, array(), $callee, $caller, $miniTrace);
524
        }
525
526
        // open the file and read it up to the position where the function call expression ended
527
        if (empty($callee['class'])) {
528
            $callfunc = $callee['function'];
529
        } else {
530
            $callfunc = array($callee['class'], $callee['function']);
531
        }
532
533
        $calls = CallFinder::getFunctionCalls(
534
            file_get_contents($callee['file']),
535
            $callee['line'],
536
            $callfunc
537
        );
538
539
        $return = array(null, array(), $callee, $caller, $miniTrace);
540
541
        foreach ($calls as $call) {
542
            $is_unpack = false;
0 ignored issues
show
Coding Style introduced by
$is_unpack 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...
543
544
            // Handle argument unpacking as a last resort
545
            if (KINT_PHP56) {
546
                foreach ($call['parameters'] as $i => &$param) {
547
                    if (strpos($param['name'], '...') === 0) {
548
                        if ($i === count($call['parameters']) - 1) {
549
                            for ($j = 1; $j + $i < $num_params; ++$j) {
0 ignored issues
show
Coding Style introduced by
$num_params 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...
550
                                $call['parameters'][] = array(
551
                                    'name' => 'array_values('.substr($param['name'], 3).')['.$j.']',
552
                                    'path' => 'array_values('.substr($param['path'], 3).')['.$j.']',
553
                                    'expression' => false,
554
                                );
555
                            }
556
557
                            $param['name'] = 'reset('.substr($param['name'], 3).')';
558
                            $param['path'] = 'reset('.substr($param['path'], 3).')';
559
                            $param['expression'] = false;
560
                        } else {
561
                            $call['parameters'] = array_slice($call['parameters'], 0, $i);
562
                        }
563
564
                        $is_unpack = true;
0 ignored issues
show
Coding Style introduced by
$is_unpack 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...
565
                        break;
566
                    }
567
                }
568
            }
569
570
            if ($is_unpack || count($call['parameters']) === $num_params) {
0 ignored issues
show
Coding Style introduced by
$is_unpack 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...
571
                if ($return[0] === null) {
572
                    $return = array($call['parameters'], $call['modifiers'], $callee, $caller, $miniTrace);
573
                } else {
574
                    // If we have multiple calls on the same line with the same amount of arguments,
575
                    // we can't be sure which it is so just return null and let them figure it out
576
                    return array(null, array(), $callee, $caller, $miniTrace);
577
                }
578
            }
579
        }
580
581
        return $return;
582
    }
583
}
584