Kint_Parser_ClassMethods::getTriggers()   A
last analyzed

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
class Kint_Parser_ClassMethods extends Kint_Parser_Plugin
0 ignored issues
show
Coding Style introduced by
Kint_Parser_ClassMethods 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
    private static $cache = array();
6
7
    public function getTypes()
8
    {
9
        return array('object');
10
    }
11
12
    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...
13
    {
14
        return Kint_Parser::TRIGGER_SUCCESS;
15
    }
16
17
    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...
18
    {
19
        $class = get_class($var);
20
21
        // assuming class definition will not change inside one request
22
        if (!isset(self::$cache[$class])) {
23
            $methods = array();
24
25
            $reflection = new ReflectionClass($class);
26
27
            foreach ($reflection->getMethods() as $method) {
28
                $methods[] = new Kint_Object_Method($method);
29
            }
30
31
            usort($methods, array('Kint_Parser_ClassMethods', 'sort'));
32
33
            self::$cache[$class] = $methods;
34
        }
35
36
        if (!empty(self::$cache[$class])) {
37
            $rep = new Kint_Object_Representation('Available methods', 'methods');
38
39
            // Can't cache access paths
40
            foreach (self::$cache[$class] as $m) {
41
                $method = clone $m;
42
                $method->depth = $o->depth + 1;
43
44
                if (!$this->parser->childHasPath($o, $method)) {
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
45
                    $method->access_path = null;
46
                } else {
47
                    $method->setAccessPathFrom($o);
48
                }
49
50
                if ($method->owner_class !== $class) {
51
                    $ds = clone $method->getRepresentation('docstring');
52
                    $ds->class = $method->owner_class;
53
                    $method->replaceRepresentation($ds);
54
                }
55
56
                $rep->contents[] = $method;
57
            }
58
59
            $o->addRepresentation($rep);
60
        }
61
    }
62
63
    private static function sort(Kint_Object_Method $a, Kint_Object_Method $b)
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...
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...
64
    {
65
        $sort = ((int) $a->static) - ((int) $b->static);
66
        if ($sort) {
67
            return $sort;
68
        }
69
70
        $sort = Kint_Object::sortByAccess($a, $b);
71
        if ($sort) {
72
            return $sort;
73
        }
74
75
        $sort = Kint_Object_Instance::sortByHierarchy($a->owner_class, $b->owner_class);
76
        if ($sort) {
77
            return $sort;
78
        }
79
80
        return $a->startline - $b->startline;
81
    }
82
}
83