Conditions | 11 |
Paths | 13 |
Total Lines | 43 |
Code Lines | 24 |
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 |
||
73 | private function getParameterValue(\ReflectionParameter $parameter) |
||
74 | { |
||
75 | try { |
||
76 | $class = $parameter->getClass(); |
||
77 | } catch (\ReflectionException $e) { |
||
78 | // TODO: Log |
||
79 | return null; |
||
80 | } |
||
81 | |||
82 | if ($class === null) { |
||
83 | |||
84 | if ($parameter->isArray()) { |
||
85 | |||
86 | if ($parameter->name == 'parameters') { |
||
87 | return $this->route->getParameters(); |
||
88 | } elseif ($parameter->name == 'arguments') { |
||
89 | return $this->route->getArguments(); |
||
90 | } else { |
||
91 | |||
92 | try { |
||
93 | return $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : []; |
||
94 | } catch (\ReflectionException $e) { |
||
95 | // TODO: Log |
||
96 | return []; |
||
97 | } |
||
98 | |||
99 | } |
||
100 | |||
101 | } else { |
||
102 | |||
103 | try { |
||
104 | return $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null; |
||
105 | } catch (\ReflectionException $e) { |
||
106 | // TODO: Log |
||
107 | return null; |
||
108 | } |
||
109 | |||
110 | } |
||
111 | |||
112 | } elseif ($parameter->getClass()->name == Context::class) { |
||
113 | return $this->context; |
||
114 | } else { |
||
115 | return $this->context->getSingletons()->get($parameter->getClass()->name); |
||
116 | } |
||
119 |