Conditions | 20 |
Paths | 8448 |
Total Lines | 60 |
Code Lines | 39 |
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 |
||
38 | public function __construct(BasicObject $base, array $raw_frame) |
||
39 | { |
||
40 | parent::__construct(); |
||
41 | |||
42 | $this->transplant($base); |
||
43 | |||
44 | $this->trace = array( |
||
45 | 'function' => isset($raw_frame['function']) ? $raw_frame['function'] : null, |
||
46 | 'line' => isset($raw_frame['line']) ? $raw_frame['line'] : null, |
||
47 | 'file' => isset($raw_frame['file']) ? $raw_frame['file'] : null, |
||
48 | 'class' => isset($raw_frame['class']) ? $raw_frame['class'] : null, |
||
49 | 'type' => isset($raw_frame['type']) ? $raw_frame['type'] : null, |
||
50 | 'object' => null, |
||
51 | 'args' => null, |
||
52 | ); |
||
53 | |||
54 | if ($this->trace['class'] && \method_exists($this->trace['class'], $this->trace['function'])) { |
||
|
|||
55 | $func = new ReflectionMethod($this->trace['class'], $this->trace['function']); |
||
56 | $this->trace['function'] = new MethodObject($func); |
||
57 | } elseif (!$this->trace['class'] && \function_exists($this->trace['function'])) { |
||
58 | $func = new ReflectionFunction($this->trace['function']); |
||
59 | $this->trace['function'] = new MethodObject($func); |
||
60 | } |
||
61 | |||
62 | foreach ($this->value->contents as $frame_prop) { |
||
63 | if ('object' === $frame_prop->name) { |
||
64 | $this->trace['object'] = $frame_prop; |
||
65 | $this->trace['object']->name = null; |
||
66 | $this->trace['object']->operator = BasicObject::OPERATOR_NONE; |
||
67 | } |
||
68 | if ('args' === $frame_prop->name) { |
||
69 | $this->trace['args'] = $frame_prop->value->contents; |
||
70 | |||
71 | if ($this->trace['function'] instanceof MethodObject) { |
||
72 | foreach (\array_values($this->trace['function']->parameters) as $param) { |
||
73 | if (isset($this->trace['args'][$param->position])) { |
||
74 | $this->trace['args'][$param->position]->name = $param->getName(); |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | |||
81 | $this->clearRepresentations(); |
||
82 | |||
83 | if (isset($this->trace['file'], $this->trace['line']) && \is_readable($this->trace['file'])) { |
||
84 | $this->addRepresentation(new SourceRepresentation($this->trace['file'], $this->trace['line'])); |
||
85 | } |
||
86 | |||
87 | if ($this->trace['args']) { |
||
88 | $args = new Representation('Arguments'); |
||
89 | $args->contents = $this->trace['args']; |
||
90 | $this->addRepresentation($args); |
||
91 | } |
||
92 | |||
93 | if ($this->trace['object']) { |
||
94 | $callee = new Representation('object'); |
||
95 | $callee->label = 'Callee object ['.$this->trace['object']->classname.']'; |
||
96 | $callee->contents[] = $this->trace['object']; |
||
97 | $this->addRepresentation($callee); |
||
98 | } |
||
101 |