| Conditions | 10 |
| Paths | 14 |
| Total Lines | 38 |
| Code Lines | 24 |
| 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 |
||
| 56 | public function wrap(array $args): array |
||
| 57 | { |
||
| 58 | $result = []; |
||
| 59 | foreach ($args as $arg) { |
||
| 60 | $display = $type = strtolower(gettype($arg)); |
||
| 61 | |||
| 62 | if (is_numeric($arg)) { |
||
| 63 | $result[] = $this->r->apply($arg, 'value', $type); |
||
| 64 | continue; |
||
| 65 | } elseif (is_bool($arg)) { |
||
| 66 | $result[] = $this->r->apply($arg ? 'true' : 'false', 'value', $type); |
||
| 67 | continue; |
||
| 68 | } elseif (is_null($arg)) { |
||
| 69 | $result[] = $this->r->apply('null', 'value', $type); |
||
| 70 | continue; |
||
| 71 | } |
||
| 72 | |||
| 73 | if (is_object($arg)) { |
||
| 74 | $reflection = new \ReflectionClass($arg); |
||
| 75 | $display = sprintf('<span title="%s">%s</span>', $reflection->getName(), $reflection->getShortName()); |
||
| 76 | } |
||
| 77 | |||
| 78 | $type = $this->r->apply($display, 'value', $type); |
||
| 79 | |||
| 80 | if ($this->verbosity < HandlerInterface::VERBOSITY_DEBUG) { |
||
| 81 | $result[] = sprintf('<span>%s</span>', $type); |
||
| 82 | } else { |
||
| 83 | $hash = is_object($arg) ? spl_object_hash($arg) : md5(json_encode($arg)); |
||
| 84 | |||
| 85 | if (!isset($this->values[$hash])) { |
||
| 86 | $this->values[$hash] = $this->dumper->dump($arg, Dumper::RETURN); |
||
| 87 | } |
||
| 88 | |||
| 89 | $result[] = sprintf('<span onclick="_da(\'%s\')">%s</span>', $hash, $type); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | return $result; |
||
| 94 | } |
||
| 106 |