Conditions | 16 |
Paths | 265 |
Total Lines | 110 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
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 |
||
22 | public function parse(&$var, Kint_Object &$o, $trigger) |
||
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'); |
||
38 | |||
39 | $base_obj = new Kint_Object(); |
||
40 | $base_obj->depth = $o->depth; |
||
41 | |||
42 | if ($o->access_path) { |
||
43 | $base_obj->access_path = '(string) '.$o->access_path; |
||
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; |
||
57 | $this->parser->max_depth = 0; |
||
58 | $a->contents = $this->parser->parse($attribs, $base_obj); |
||
59 | $this->parser->max_depth = $depth_stash; |
||
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'); |
||
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(); |
||
84 | $base_obj->depth = $o->depth + 1; |
||
85 | $base_obj->name = $value->name; |
||
86 | if ($value->access_path) { |
||
87 | $base_obj->access_path = $value->access_path.'['.$i.']'; |
||
88 | } |
||
89 | |||
90 | $value = $this->parser->parse($children->{$value->name}[$i], $base_obj); |
||
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(); |
||
110 | $base_obj->depth = $o->depth + 1; |
||
111 | $base_obj->name = $o->name; |
||
112 | if ($o->access_path) { |
||
113 | $base_obj->access_path = '(string) '.$o->access_path; |
||
114 | } |
||
115 | |||
116 | $value = (string) $var; |
||
117 | |||
118 | $depth_stash = $this->parser->max_depth; |
||
119 | $this->parser->max_depth = 0; |
||
120 | $value = $this->parser->parse($value, $base_obj); |
||
121 | $this->parser->max_depth = $depth_stash; |
||
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 |
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.