Kint_Parser_SimpleXMLElement   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 130
rs 10
c 0
b 0
f 0
wmc 18
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypes() 0 4 1
A getTriggers() 0 4 1
F parse() 0 110 16
1
<?php
2
3
class Kint_Parser_SimpleXMLElement extends Kint_Parser_Plugin
0 ignored issues
show
Coding Style introduced by
Kint_Parser_SimpleXMLElement 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...
4
{
5
    /**
6
     * Show all properties and methods.
7
     *
8
     * @var bool
9
     */
10
    public static $verbose = false;
11
12
    public function getTypes()
13
    {
14
        return array('object');
15
    }
16
17
    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...
18
    {
19
        return Kint_Parser::TRIGGER_SUCCESS;
20
    }
21
22
    public function parse(&$var, Kint_Object &$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...
23
    {
24
        if (!$var instanceof SimpleXMLElement) {
25
            return;
26
        }
27
28
        $o->hints[] = 'simplexml_element';
29
30
        if (!self::$verbose) {
31
            $o->removeRepresentation('properties');
32
            $o->removeRepresentation('iterator');
33
            $o->removeRepresentation('methods');
34
        }
35
36
        // Attributes
37
        $a = new Kint_Object_Representation('Attributes');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. 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...
38
39
        $base_obj = new Kint_Object();
0 ignored issues
show
Coding Style introduced by
$base_obj 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
        $base_obj->depth = $o->depth;
0 ignored issues
show
Coding Style introduced by
$base_obj 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
42
        if ($o->access_path) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $o->access_path of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
43
            $base_obj->access_path = '(string) '.$o->access_path;
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
44
        }
45
46
        if ($var->attributes()) {
47
            $attribs = iterator_to_array($var->attributes());
48
            $attribs = array_map('strval', $attribs);
49
        } else {
50
            $attribs = array();
51
        }
52
53
        // XML attributes are by definition strings and don't have children,
54
        // so up the depth limit in case we're just below the limit since
55
        // there won't be any recursive stuff anyway.
56
        $depth_stash = $this->parser->max_depth;
0 ignored issues
show
Coding Style introduced by
$depth_stash 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...
57
        $this->parser->max_depth = 0;
58
        $a->contents = $this->parser->parse($attribs, $base_obj);
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
Documentation Bug introduced by
It seems like $this->parser->parse($attribs, $base_obj) of type object<Kint_Object> is incompatible with the declared type array of property $contents.

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...
59
        $this->parser->max_depth = $depth_stash;
0 ignored issues
show
Coding Style introduced by
$depth_stash 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...
60
61
        $a->contents = $a->contents->value->contents;
62
63
        $o->addRepresentation($a, 0);
64
65
        // Children
66
        // We need to check children() separately from the values we already parsed because
67
        // text contents won't show up in children() but they will show up in properties.
68
        //
69
        // Why do we still need to check for attributes if we already have an attributes()
70
        // method? Hell if I know!
71
        $children = $var->children();
72
73
        if ($o->value) {
74
            $c = new Kint_Object_Representation('Children');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
75
76
            foreach ($o->value->contents as $value) {
77
                if ($value->name === '@attributes') {
78
                    continue;
79
                } elseif (isset($children->{$value->name})) {
80
                    $i = 0;
81
82
                    while (isset($children->{$value->name}[$i])) {
83
                        $base_obj = new Kint_Object();
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
84
                        $base_obj->depth = $o->depth + 1;
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
85
                        $base_obj->name = $value->name;
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
86
                        if ($value->access_path) {
87
                            $base_obj->access_path = $value->access_path.'['.$i.']';
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
88
                        }
89
90
                        $value = $this->parser->parse($children->{$value->name}[$i], $base_obj);
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
91
92
                        if ($value->access_path && $value->type === 'string') {
93
                            $value->access_path = '(string) '.$value->access_path;
94
                        }
95
96
                        $c->contents[] = $value;
97
98
                        ++$i;
99
                    }
100
                }
101
            }
102
103
            $o->size = count($c->contents);
104
105
            if (!$o->size) {
106
                $o->size = null;
107
108
                if (strlen((string) $var)) {
109
                    $base_obj = new Kint_Object_Blob();
0 ignored issues
show
Coding Style introduced by
$base_obj 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
                    $base_obj->depth = $o->depth + 1;
0 ignored issues
show
Coding Style introduced by
$base_obj 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
                    $base_obj->name = $o->name;
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
112
                    if ($o->access_path) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $o->access_path of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
113
                        $base_obj->access_path = '(string) '.$o->access_path;
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
114
                    }
115
116
                    $value = (string) $var;
117
118
                    $depth_stash = $this->parser->max_depth;
0 ignored issues
show
Coding Style introduced by
$depth_stash 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...
119
                    $this->parser->max_depth = 0;
120
                    $value = $this->parser->parse($value, $base_obj);
0 ignored issues
show
Coding Style introduced by
$base_obj 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...
121
                    $this->parser->max_depth = $depth_stash;
0 ignored issues
show
Coding Style introduced by
$depth_stash 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...
122
123
                    $c = new Kint_Object_Representation('Contents');
124
                    $c->implicit_label = true;
125
                    $c->contents = array($value);
126
                }
127
            }
128
129
            $o->addRepresentation($c, 0);
130
        }
131
    }
132
}
133