Kint_Parser_DOMIterator::getTriggers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class Kint_Parser_DOMIterator extends Kint_Parser_Plugin
0 ignored issues
show
Coding Style introduced by
Kint_Parser_DOMIterator 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
    public function getTypes()
6
    {
7
        return array('object');
8
    }
9
10
    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...
11
    {
12
        // Recursion should never happen, should always be stopped at the parent
13
        // DOMNode.  Depth limit on the other hand we're going to skip since
14
        // that would show an empty iterator and rather useless. Let the depth
15
        // limit hit the children (DOMNodeList only has DOMNode as children)
16
        return Kint_Parser::TRIGGER_COMPLETE & ~Kint_Parser::TRIGGER_RECURSION;
17
    }
18
19
    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...
20
    {
21
        if (!($var instanceof DOMNamedNodeMap || $var instanceof DOMNodeList)) {
22
            return;
23
        }
24
25
        $o->size = $var->length;
26
        if ($o->size === 0) {
27
            $o->replaceRepresentation(new Kint_Object_Representation('Iterator'));
28
            $o->size = null;
29
30
            return;
31
        }
32
33
        // Depth limit
34
        // Make empty iterator representation since we need it in DOMNode to point out depth limits
35
        if ($this->parser->max_depth && $o->depth + 1 >= $this->parser->max_depth) {
36
            $b = new Kint_Object();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. 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...
37
            $b->name = $o->classname.' Iterator Contents';
0 ignored issues
show
Bug introduced by
The property classname does not seem to exist in Kint_Object.

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...
38
            $b->access_path = 'iterator_to_array('.$o->access_path.')';
39
            $b->depth = $o->depth + 1;
40
            $b->hints[] = 'depth_limit';
41
42
            $r = new Kint_Object_Representation('Iterator');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. 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...
43
            $r->contents = array($b);
44
            $o->replaceRepresentation($r, 0);
45
46
            return;
47
        }
48
49
        // In 5.1 you can interate them but they're not traversable.
50
        // DomDoc. The gift that keeps on giving.
51
        if (!$var instanceof Traversable) {
52
            $data = array();
53
            foreach ($var as $item) {
54
                $data[] = $item;
55
            }
56
        } else {
57
            $data = iterator_to_array($var);
58
        }
59
60
        $r = new Kint_Object_Representation('Iterator');
61
        $o->replaceRepresentation($r, 0);
62
63
        foreach ($data as $key => $item) {
64
            $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...
65
            $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...
66
            $base_obj->name = $item->nodeName;
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...
67
68
            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...
69
                if ($var instanceof DOMNamedNodeMap) {
70
                    $base_obj->access_path = $o->access_path.'->getNamedItem('.var_export($key, true).')';
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...
71
                } elseif ($var instanceof DOMNodeList) {
72
                    $base_obj->access_path = $o->access_path.'->item('.var_export($key, true).')';
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...
73
                } else {
74
                    $base_obj->access_path = 'iterator_to_array('.$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...
75
                }
76
            }
77
78
            $r->contents[] = $this->parser->parse($item, $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...
79
        }
80
    }
81
}
82