| Conditions | 10 |
| Paths | 36 |
| Total Lines | 31 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 35 | public function collect() |
||
| 36 | { |
||
| 37 | $result = CacheProxy::getData(); |
||
| 38 | |||
| 39 | $keys = []; |
||
| 40 | $showGet = $this->showGet || isset($_REQUEST['debug_cacheshowget']); |
||
| 41 | foreach ($result as $k => $v) { |
||
| 42 | $type = $v['type'] ?? null; |
||
| 43 | if (!$showGet && $type == "get") { |
||
| 44 | continue; |
||
| 45 | } |
||
| 46 | $val = $v['value']; |
||
| 47 | if (!is_string($val)) { |
||
| 48 | $val = json_encode($val); |
||
| 49 | } |
||
| 50 | // Long values are trimmed by DebugBar js |
||
| 51 | if (!empty($v['ttl'])) { |
||
| 52 | $val .= " - TTL: " . $v['ttl']; |
||
| 53 | } |
||
| 54 | if (!empty($v['caller'])) { |
||
| 55 | $val .= " - (" . $v['caller'] . ")"; |
||
| 56 | } |
||
| 57 | if ($type == 'set' && $showGet) { |
||
| 58 | $val = "SET - " . $val; |
||
| 59 | } |
||
| 60 | $keys[$v['key']] = $val; |
||
| 61 | } |
||
| 62 | |||
| 63 | return [ |
||
| 64 | 'count' => count($keys), |
||
| 65 | 'keys' => $keys |
||
| 66 | ]; |
||
| 106 |