Conditions | 15 |
Paths | 20 |
Total Lines | 43 |
Code Lines | 21 |
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 |
||
69 | public function toHeadersFilter($els, $options = array ()) |
||
70 | { |
||
71 | |||
72 | $fields = isset($options['fields']) |
||
73 | ? $options['fields'] |
||
74 | : array() |
||
75 | ; |
||
76 | |||
77 | $headers = array(); |
||
78 | |||
79 | foreach ($els as $el) { |
||
|
|||
80 | |||
81 | if (is_object($el)) { |
||
82 | |||
83 | foreach ($this->getGettersWithoutParameters($el) as $method) { |
||
84 | preg_match('#get(?P<name>.*)#', $method->name, $matches); |
||
85 | $name = strtolower($matches['name']); |
||
86 | if (!in_array($name, $headers) && (0 === count($fields) || array_key_exists($name, $fields))) { |
||
87 | $headers[$name] = array_key_exists($name, $fields) |
||
88 | ? $fields[$name] |
||
89 | : $name |
||
90 | ; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | } elseif (is_array($el)) { |
||
95 | |||
96 | foreach ($el as $key => $value) { |
||
97 | if (!in_array($key, $headers) && (0 === count($fields) || array_key_exists($key, $fields))) { |
||
98 | $headers[$key] = array_key_exists($key, $fields) |
||
99 | ? $fields[$key] |
||
100 | : $key |
||
101 | ; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | } |
||
106 | |||
107 | } |
||
108 | |||
109 | return $headers; |
||
110 | |||
111 | } |
||
112 | |||
169 |