|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kint_Parser_ClassMethods extends Kint_Parser_Plugin |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
private static $cache = array(); |
|
6
|
|
|
|
|
7
|
|
|
public function getTypes() |
|
8
|
|
|
{ |
|
9
|
|
|
return array('object'); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
public function getTriggers() |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
return Kint_Parser::TRIGGER_SUCCESS; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function parse(&$var, Kint_Object &$o, $trigger) |
|
|
|
|
|
|
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)) { |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
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
|
|
|
|
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.