| Conditions | 10 |
| Paths | 48 |
| Total Lines | 28 |
| Code Lines | 15 |
| 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 |
||
| 129 | public function toArray() |
||
| 130 | { |
||
| 131 | $array = $this->fields; |
||
| 132 | |||
| 133 | foreach ($this->appends as $accessor) { |
||
| 134 | if (isset($this[$accessor])) { |
||
| 135 | $array[$accessor] = $this[$accessor]; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | foreach ($this->related as $key => $value) { |
||
| 140 | if (is_object($value) && method_exists($value, 'toArray')) { |
||
| 141 | $array[$key] = $value->toArray(); |
||
| 142 | } elseif (is_null($value) || $value === false) { |
||
| 143 | $array[$key] = $value; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | if (count($this->getVisible()) > 0) { |
||
| 148 | $array = array_intersect_key($array, array_flip($this->getVisible())); |
||
| 149 | } |
||
| 150 | |||
| 151 | if (count($this->getHidden()) > 0) { |
||
| 152 | $array = array_diff_key($array, array_flip($this->getHidden())); |
||
| 153 | } |
||
| 154 | |||
| 155 | return $array; |
||
| 156 | } |
||
| 157 | |||
| 170 |