Test Setup Failed
Push — next ( 738e04...b06172 )
by Jonathan
25:05
created

TracePlugin::normalizeAliases()   D

Complexity

Conditions 9
Paths 6

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 22
nc 6
nop 1
dl 0
loc 32
rs 4.909
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Parser;
4
5
use Kint\Object\BasicObject;
6
use Kint\Object\TraceFrameObject;
7
use Kint\Object\TraceObject;
8
use Kint\Utils;
9
10
class TracePlugin extends Plugin
11
{
12
    public static $blacklist = array('spl_autoload_call');
13
14
    public function getTypes()
15
    {
16
        return array('array');
17
    }
18
19
    public function getTriggers()
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...
20
    {
21
        return Parser::TRIGGER_SUCCESS;
22
    }
23
24
    public function parse(&$var, BasicObject &$o, $trigger)
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...
25
    {
26
        if (!$o->value) {
27
            return;
28
        }
29
30
        $trace = $this->parser->getCleanArray($var);
31
32
        if (count($trace) !== count($o->value->contents) || !Utils::isTrace($trace)) {
33
            return;
34
        }
35
36
        $o = $o->transplant(new TraceObject());
37
        $rep = $o->value;
38
39
        $old_trace = $rep->contents;
0 ignored issues
show
Coding Style introduced by
$old_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...
40
41
        Utils::normalizeAliases(self::$blacklist);
42
43
        $rep->contents = array();
44
45
        foreach ($old_trace as $frame) {
0 ignored issues
show
Coding Style introduced by
$old_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...
46
            $index = $frame->name;
47
48
            if (!isset($trace[$index]['function'])) {
49
                // Something's very very wrong here, but it's probably a plugin's fault
50
                continue;
51
            }
52
53
            if (Utils::traceFrameIsListed($trace[$index], self::$blacklist)) {
54
                continue;
55
            }
56
57
            $rep->contents[$index] = $frame->transplant(new TraceFrameObject());
58
            $rep->contents[$index]->assignFrame($trace[$index]);
59
        }
60
61
        ksort($rep->contents);
62
        $rep->contents = array_values($rep->contents);
63
64
        $o->clearRepresentations();
65
        $o->addRepresentation($rep);
66
        $o->size = count($rep->contents);
67
    }
68
}
69