| Conditions | 10 |
| Paths | 16 |
| Total Lines | 36 |
| Code Lines | 18 |
| 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 |
||
| 67 | protected function formatMessage(array $data = []) |
||
| 68 | { |
||
| 69 | $params = array_merge($this->message, $data); |
||
| 70 | |||
| 71 | foreach ($params as $key => $value) { |
||
| 72 | if (in_array($key, $this->required, true) && empty($value) && empty($this->message[$key])) { |
||
| 73 | throw new InvalidArgumentException(sprintf('Attribute "%s" can not be empty!', $key)); |
||
| 74 | } |
||
| 75 | |||
| 76 | $params[$key] = empty($value) ? $this->message[$key] : $value; |
||
| 77 | } |
||
| 78 | |||
| 79 | foreach ($params['data'] as $key => $value) { |
||
| 80 | if (is_array($value)) { |
||
| 81 | if (isset($value['value'])) { |
||
| 82 | $params['data'][$key] = ['value' => $value['value']]; |
||
| 83 | |||
| 84 | continue; |
||
| 85 | } |
||
| 86 | |||
| 87 | if (count($value) >= 1) { |
||
| 88 | $value = [ |
||
| 89 | 'value' => $value[0], |
||
| 90 | // 'color' => $value[1],// color unsupported |
||
| 91 | ]; |
||
| 92 | } |
||
| 93 | } else { |
||
| 94 | $value = [ |
||
| 95 | 'value' => strval($value), |
||
| 96 | ]; |
||
| 97 | } |
||
| 98 | |||
| 99 | $params['data'][$key] = $value; |
||
| 100 | } |
||
| 101 | |||
| 102 | return $params; |
||
| 103 | } |
||
| 113 |