| Conditions | 12 |
| Paths | 6 |
| Total Lines | 36 |
| Code Lines | 18 |
| 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 |
||
| 113 | public function toArrayFilter($el, $options = array ()) |
||
| 114 | { |
||
| 115 | |||
| 116 | $fields = isset($options['fields']) |
||
| 117 | ? $options['fields'] |
||
| 118 | : array() |
||
| 119 | ; |
||
| 120 | |||
| 121 | $values = array(); |
||
| 122 | |||
| 123 | if (is_object($el)) { |
||
| 124 | |||
| 125 | foreach ($this->getGettersWithoutParameters($el) as $method) { |
||
| 126 | preg_match('#get(?P<name>.*)#', $method->name, $matches); |
||
| 127 | |||
| 128 | $name = strtolower($matches['name']); |
||
| 129 | if (0 === count($fields) || array_key_exists($name, $fields)) { |
||
| 130 | $value = $el->{$method->name}(); |
||
| 131 | if (!is_object($value) && !is_array($value)) { |
||
| 132 | $values[$name] = $value; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | } elseif (is_array($el)) { |
||
| 138 | |||
| 139 | foreach ($el as $key => $value) { |
||
| 140 | if (!is_object($value) && !is_array($value)) { |
||
| 141 | $values[$key] = $value; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | } |
||
| 146 | |||
| 147 | return $values; |
||
| 148 | } |
||
| 149 | |||
| 169 |