Conditions | 16 |
Paths | 728 |
Total Lines | 98 |
Code Lines | 61 |
Lines | 15 |
Ratio | 15.31 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
17 | public function parse(&$var, Kint_Object &$o, $trigger) |
||
18 | { |
||
19 | $class = get_class($var); |
||
20 | $reflection = new ReflectionClass($class); |
||
21 | |||
22 | // Constants |
||
23 | // TODO: PHP 7.1 allows private consts but reflection doesn't have a way to check them yet |
||
24 | if (!isset(self::$cache[$class])) { |
||
25 | $consts = array(); |
||
26 | |||
27 | foreach ($reflection->getConstants() as $name => $val) { |
||
28 | $const = Kint_Object::blank($name); |
||
29 | $const->const = true; |
||
30 | $const->depth = $o->depth + 1; |
||
31 | $const->owner_class = $class; |
||
32 | View Code Duplication | if (KINT_PHP53) { |
|
33 | $const->access_path = '\\'.$class.'::'.$const->name; |
||
34 | } else { |
||
35 | $const->access_path = $class.'::'.$const->name; |
||
36 | } |
||
37 | $const->operator = Kint_Object::OPERATOR_STATIC; |
||
38 | $const = $this->parser->parse($val, $const); |
||
39 | |||
40 | $consts[] = $const; |
||
41 | } |
||
42 | |||
43 | self::$cache[$class] = $consts; |
||
44 | } |
||
45 | |||
46 | $statics = new Kint_Object_Representation('Static class properties', 'statics'); |
||
47 | $statics->contents = self::$cache[$class]; |
||
48 | |||
49 | // Statics |
||
50 | |||
51 | if (!KINT_PHP53) { |
||
52 | $static_map = $reflection->getStaticProperties(); |
||
53 | } |
||
54 | |||
55 | foreach ($reflection->getProperties(ReflectionProperty::IS_STATIC) as $static) { |
||
56 | $prop = new Kint_Object(); |
||
57 | $prop->name = '$'.$static->getName(); |
||
58 | $prop->depth = $o->depth + 1; |
||
59 | $prop->static = true; |
||
60 | $prop->operator = Kint_Object::OPERATOR_STATIC; |
||
61 | |||
62 | if (KINT_PHP53) { |
||
63 | $prop->owner_class = $static->getDeclaringClass()->name; |
||
64 | } else { |
||
65 | // getDeclaringClass() is broke in old PHP versions, but getProperties() will only |
||
66 | // return accessible properties and we can access them through the parent class so |
||
67 | // we can just put the parent class here. It's not an accurate portrayal of where |
||
68 | // the static comes from, but it shows a working access path so it's good enough |
||
69 | $prop->owner_class = $class; |
||
70 | } |
||
71 | |||
72 | $prop->access = Kint_Object::ACCESS_PUBLIC; |
||
73 | View Code Duplication | if ($static->isProtected()) { |
|
74 | $prop->access = Kint_Object::ACCESS_PROTECTED; |
||
75 | } elseif ($static->isPrivate()) { |
||
76 | $prop->access = Kint_Object::ACCESS_PRIVATE; |
||
77 | } |
||
78 | |||
79 | if ($this->parser->childHasPath($o, $prop)) { |
||
80 | View Code Duplication | if (KINT_PHP53) { |
|
81 | $prop->access_path = '\\'.$prop->owner_class.'::'.$prop->name; |
||
82 | } else { |
||
83 | $prop->access_path = $prop->owner_class.'::'.$prop->name; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | if (KINT_PHP53) { |
||
88 | $static->setAccessible(true); |
||
89 | $val = $static->getValue(); |
||
90 | } else { |
||
91 | switch ($prop->access) { |
||
92 | case Kint_Object::ACCESS_PUBLIC: |
||
93 | $val = $static_map[$static->getName()]; |
||
94 | break; |
||
95 | case Kint_Object::ACCESS_PROTECTED: |
||
96 | $val = $static_map["\0*\0".$static->getName()]; |
||
97 | break; |
||
98 | case Kint_Object::ACCESS_PRIVATE: |
||
99 | $val = $static_map["\0".$class."\0".$static->getName()]; |
||
100 | break; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | $statics->contents[] = $this->parser->parse($val, $prop); |
||
105 | } |
||
106 | |||
107 | if (empty($statics->contents)) { |
||
108 | return; |
||
109 | } |
||
110 | |||
111 | usort($statics->contents, array('Kint_Parser_ClassStatics', 'sort')); |
||
112 | |||
113 | $o->addRepresentation($statics); |
||
114 | } |
||
115 | |||
131 |
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.