| Conditions | 13 |
| Paths | 48 |
| Total Lines | 48 |
| Code Lines | 28 |
| 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 |
||
| 70 | public function current() |
||
| 71 | { |
||
| 72 | $row = parent::current(); |
||
| 73 | if ($this->callback) { |
||
| 74 | $row = $this->callback->__invoke($row); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($this->skipFields) { |
||
|
|
|||
| 78 | foreach ($this->skipFields as $field) { |
||
| 79 | if (isset($row[$field])) { |
||
| 80 | unset($row[$field]); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | $keys = null; |
||
| 86 | |||
| 87 | if ($this->combineOffset) { |
||
| 88 | foreach ($this->combineOffset as $offsetKey => $offsetValue) { |
||
| 89 | $keys = array_keys($row); |
||
| 90 | $row[$row[$keys[$offsetKey]]] = $row[$keys[$offsetValue]]; |
||
| 91 | unset($row[$keys[$offsetKey]]); |
||
| 92 | unset($row[$keys[$offsetValue]]); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($this->combineFields) { |
||
| 97 | foreach ($this->combineFields as $fieldKey => $fieldValue) { |
||
| 98 | $row[$row[$fieldKey]] = $row[$fieldValue]; |
||
| 99 | unset($row[$fieldKey]); |
||
| 100 | unset($row[$fieldValue]); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($this->changeKeys) { |
||
| 105 | if (!$keys) { |
||
| 106 | $keys = array_keys($row); |
||
| 107 | } |
||
| 108 | foreach ($keys as &$key) { |
||
| 109 | if (isset($this->changeKeys[$key])) { |
||
| 110 | $key = $this->changeKeys[$key]; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | unset($key); |
||
| 114 | $row = array_combine($keys, $row); |
||
| 115 | } |
||
| 116 | |||
| 117 | return $row; |
||
| 118 | } |
||
| 140 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.