Test Setup Failed
Push — test ( 528f91...abcbcc )
by Jonathan
03:20
created

TraceFrameObject::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
namespace Kint\Object;
4
5
use Kint\Object\Representation\Representation;
6
use Kint\Object\Representation\SourceRepresentation;
7
use ReflectionFunction;
8
use ReflectionMethod;
9
10
class TraceFrameObject extends BasicObject
11
{
12
    public $trace;
13
    public $hints = array('trace_frame');
14
15
    public function assignFrame(array &$frame)
16
    {
17
        $this->trace = array(
18
            'function' => isset($frame['function']) ? $frame['function'] : null,
19
            'line' => isset($frame['line']) ? $frame['line'] : null,
20
            'file' => isset($frame['file']) ? $frame['file'] : null,
21
            'class' => isset($frame['class']) ? $frame['class'] : null,
22
            'type' => isset($frame['type']) ? $frame['type'] : null,
23
            'object' => null,
24
            'args' => null,
25
        );
26
27
        if ($this->trace['class'] && method_exists($this->trace['class'], $this->trace['function'])) {
28
            $func = new ReflectionMethod($this->trace['class'], $this->trace['function']);
29
            $this->trace['function'] = new MethodObject($func);
30
        } elseif (!$this->trace['class'] && function_exists($this->trace['function'])) {
31
            $func = new ReflectionFunction($this->trace['function']);
32
            $this->trace['function'] = new MethodObject($func);
33
        }
34
35
        foreach ($this->value->contents as $frame_prop) {
0 ignored issues
show
Coding Style introduced by
$frame_prop does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
36
            if ($frame_prop->name === 'object') {
0 ignored issues
show
Coding Style introduced by
$frame_prop does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
37
                $this->trace['object'] = $frame_prop;
0 ignored issues
show
Coding Style introduced by
$frame_prop does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
38
                $this->trace['object']->name = null;
39
                $this->trace['object']->operator = BasicObject::OPERATOR_NONE;
40
            }
41
            if ($frame_prop->name === 'args') {
0 ignored issues
show
Coding Style introduced by
$frame_prop does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
42
                $this->trace['args'] = $frame_prop->value->contents;
0 ignored issues
show
Coding Style introduced by
$frame_prop does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
43
44
                if ($this->trace['function'] instanceof MethodObject) {
45
                    foreach (array_values($this->trace['function']->parameters) as $param) {
46
                        if (isset($this->trace['args'][$param->position])) {
47
                            $this->trace['args'][$param->position]->name = $param->getName();
48
                        }
49
                    }
50
                }
51
            }
52
        }
53
54
        $this->clearRepresentations();
55
56
        if (isset($this->trace['file'], $this->trace['line']) && is_readable($this->trace['file'])) {
57
            $this->addRepresentation(new SourceRepresentation($this->trace['file'], $this->trace['line']));
58
        }
59
60
        if ($this->trace['args']) {
61
            $args = new Representation('Arguments');
62
            $args->contents = $this->trace['args'];
63
            $this->addRepresentation($args);
64
        }
65
66
        if ($this->trace['object']) {
67
            $callee = new Representation('object');
68
            $callee->label = 'Callee object ['.$this->trace['object']->classname.']';
69
            $callee->contents[] = $this->trace['object'];
70
            $this->addRepresentation($callee);
71
        }
72
    }
73
}
74