Completed
Pull Request — master (#546)
by Richard
09:47
created

Kint_Object_TraceFrame::assignFrame()   F

Complexity

Conditions 20
Paths 8448

Size

Total Lines 58
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 38
nc 8448
nop 1
dl 0
loc 58
rs 3.2761
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
class Kint_Object_TraceFrame extends Kint_Object
4
{
5
    public $trace;
6
    public $hints = array('trace_frame');
7
8
    public function assignFrame(array &$frame)
9
    {
10
        $this->trace = array(
11
            'function' => isset($frame['function']) ? $frame['function'] : null,
12
            'line' => isset($frame['line']) ? $frame['line'] : null,
13
            'file' => isset($frame['file']) ? $frame['file'] : null,
14
            'class' => isset($frame['class']) ? $frame['class'] : null,
15
            'type' => isset($frame['type']) ? $frame['type'] : null,
16
            'object' => null,
17
            'args' => null,
18
        );
19
20
        if ($this->trace['class'] && method_exists($this->trace['class'], $this->trace['function'])) {
21
            $func = new ReflectionMethod($this->trace['class'], $this->trace['function']);
22
            $this->trace['function'] = new Kint_Object_Method($func);
23
        } elseif (!$this->trace['class'] && function_exists($this->trace['function'])) {
24
            $func = new ReflectionFunction($this->trace['function']);
25
            $this->trace['function'] = new Kint_Object_Method($func);
26
        }
27
28
        foreach ($this->value->contents as $frame_prop) {
29
            if ($frame_prop->name === 'object') {
30
                $this->trace['object'] = $frame_prop;
31
                $this->trace['object']->name = null;
32
                $this->trace['object']->operator = Kint_Object::OPERATOR_NONE;
33
            }
34
            if ($frame_prop->name === 'args') {
35
                $this->trace['args'] = $frame_prop->value->contents;
36
37
                if (is_object($this->trace['function'])) {
38
                    foreach (array_values($this->trace['function']->parameters) as $param) {
39
                        if (isset($this->trace['args'][$param->position])) {
40
                            $this->trace['args'][$param->position]->name = $param->getName();
41
                        }
42
                    }
43
                }
44
            }
45
        }
46
47
        $this->clearRepresentations();
48
49
        if (isset($this->trace['file'], $this->trace['line']) && is_readable($this->trace['file'])) {
50
            $this->addRepresentation(new Kint_Object_Representation_Source($this->trace['file'], $this->trace['line']));
51
        }
52
53
        if ($this->trace['args']) {
54
            $args = new Kint_Object_Representation('Arguments');
55
            $args->contents = $this->trace['args'];
56
            $this->addRepresentation($args);
57
        }
58
59
        if ($this->trace['object']) {
60
            $callee = new Kint_Object_Representation('object');
61
            $callee->label = 'Callee object ['.$this->trace['object']->classname.']';
62
            $callee->contents[] = $this->trace['object'];
63
            $this->addRepresentation($callee);
64
        }
65
    }
66
}
67