| Conditions | 21 |
| Paths | 1572 |
| Total Lines | 129 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 185 | private function parseObject(&$var, Kint_Object $o) |
||
| 186 | { |
||
| 187 | if (KINT_PHP53 || function_exists('spl_object_hash')) { |
||
| 188 | $hash = spl_object_hash($var); |
||
| 189 | } else { |
||
| 190 | ob_start(); |
||
| 191 | var_dump($var); |
||
|
|
|||
| 192 | preg_match('/#(\d+)/', ob_get_clean(), $match); |
||
| 193 | $hash = $match[1]; |
||
| 194 | } |
||
| 195 | |||
| 196 | $values = (array) $var; |
||
| 197 | |||
| 198 | $object = $o->transplant(new Kint_Object_Instance()); |
||
| 199 | $object->classname = get_class($var); |
||
| 200 | $object->hash = $hash; |
||
| 201 | $object->size = count($values); |
||
| 202 | |||
| 203 | if (isset($this->object_hashes[$hash])) { |
||
| 204 | $object->hints[] = 'recursion'; |
||
| 205 | |||
| 206 | $this->applyPlugins($var, $object, self::TRIGGER_RECURSION); |
||
| 207 | |||
| 208 | return $object; |
||
| 209 | } |
||
| 210 | |||
| 211 | $this->object_hashes[$hash] = $object; |
||
| 212 | |||
| 213 | if ($this->max_depth && $o->depth >= $this->max_depth) { |
||
| 214 | $object->hints[] = 'depth_limit'; |
||
| 215 | |||
| 216 | $this->applyPlugins($var, $object, self::TRIGGER_DEPTH_LIMIT); |
||
| 217 | unset($this->object_hashes[$hash]); |
||
| 218 | |||
| 219 | return $object; |
||
| 220 | } |
||
| 221 | |||
| 222 | // ArrayObject (and maybe ArrayIterator, did not try yet) unsurprisingly |
||
| 223 | // consist of mainly dark magic. What bothers me most, var_dump sees no |
||
| 224 | // problem with it, and ArrayObject also uses a custom, undocumented |
||
| 225 | // serialize function, so you can see the properties in internal functions, |
||
| 226 | // but can never iterate some of them if the flags are not STD_PROP_LIST. Fun stuff. |
||
| 227 | if ($var instanceof ArrayObject) { |
||
| 228 | $ArrayObject_flags_stash = $var->getFlags(); |
||
| 229 | $var->setFlags(ArrayObject::STD_PROP_LIST); |
||
| 230 | } |
||
| 231 | |||
| 232 | $reflector = new ReflectionObject($var); |
||
| 233 | |||
| 234 | if ($reflector->isUserDefined()) { |
||
| 235 | $object->filename = $reflector->getFileName(); |
||
| 236 | $object->startline = $reflector->getStartLine(); |
||
| 237 | } |
||
| 238 | |||
| 239 | $rep = new Kint_Object_Representation('Properties'); |
||
| 240 | |||
| 241 | if (KINT_PHP522) { |
||
| 242 | $copy = array_values($values); |
||
| 243 | } |
||
| 244 | |||
| 245 | $i = 0; |
||
| 246 | |||
| 247 | // Reflection will not show parent classes private properties, and if a |
||
| 248 | // property was unset it will happly trigger a notice looking for it. |
||
| 249 | foreach ($values as $key => &$val) { |
||
| 250 | // Casting object to array: |
||
| 251 | // private properties show in the form "\0$owner_class_name\0$property_name"; |
||
| 252 | // protected properties show in the form "\0*\0$property_name"; |
||
| 253 | // public properties show in the form "$property_name"; |
||
| 254 | // http://www.php.net/manual/en/language.types.array.php#language.types.array.casting |
||
| 255 | |||
| 256 | $child = new Kint_Object(); |
||
| 257 | $child->depth = $object->depth + 1; |
||
| 258 | $child->owner_class = $object->classname; |
||
| 259 | $child->operator = Kint_Object::OPERATOR_OBJECT; |
||
| 260 | $child->access = Kint_Object::ACCESS_PUBLIC; |
||
| 261 | |||
| 262 | $split_key = explode("\0", $key, 3); |
||
| 263 | |||
| 264 | if (count($split_key) === 3 && $split_key[0] === '') { |
||
| 265 | $child->name = $split_key[2]; |
||
| 266 | if ($split_key[1] === '*') { |
||
| 267 | $child->access = Kint_Object::ACCESS_PROTECTED; |
||
| 268 | } else { |
||
| 269 | $child->access = Kint_Object::ACCESS_PRIVATE; |
||
| 270 | $child->owner_class = $split_key[1]; |
||
| 271 | } |
||
| 272 | } elseif (KINT_PHP72) { |
||
| 273 | $child->name = (string) $key; |
||
| 274 | } else { |
||
| 275 | $child->name = $key; |
||
| 276 | } |
||
| 277 | |||
| 278 | if ($this->childHasPath($object, $child)) { |
||
| 279 | $child->access_path = $object->access_path; |
||
| 280 | |||
| 281 | if (!KINT_PHP72 && is_int($child->name)) { |
||
| 282 | $child->access_path = 'array_values((array) '.$child->access_path.')['.$i.']'; |
||
| 283 | } elseif (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $child->name)) { |
||
| 284 | $child->access_path .= '->'.$child->name; |
||
| 285 | } else { |
||
| 286 | $child->access_path .= '->{'.var_export((string) $child->name, true).'}'; |
||
| 287 | } |
||
| 288 | } |
||
| 289 | |||
| 290 | if (KINT_PHP522) { |
||
| 291 | $stash = $val; |
||
| 292 | $copy[$i] = $this->marker; |
||
| 293 | if ($val === $this->marker) { |
||
| 294 | $child->reference = true; |
||
| 295 | $val = $stash; |
||
| 296 | } |
||
| 297 | } |
||
| 298 | |||
| 299 | $rep->contents[] = $this->parse($val, $child); |
||
| 300 | ++$i; |
||
| 301 | } |
||
| 302 | |||
| 303 | if (isset($ArrayObject_flags_stash)) { |
||
| 304 | $var->setFlags($ArrayObject_flags_stash); |
||
| 305 | } |
||
| 306 | |||
| 307 | usort($rep->contents, array('Kint_Parser', 'sortObjectProperties')); |
||
| 308 | |||
| 309 | $object->addRepresentation($rep); |
||
| 310 | $this->applyPlugins($var, $object, self::TRIGGER_SUCCESS); |
||
| 311 | unset($this->object_hashes[$hash]); |
||
| 312 | |||
| 313 | return $object; |
||
| 314 | } |
||
| 471 |