| Conditions | 13 |
| Paths | 85 |
| Total Lines | 43 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 26 |
| CRAP Score | 13.4003 |
| Changes | 3 | ||
| 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 |
||
| 24 | 10 | public function getData() |
|
| 25 | { |
||
| 26 | 10 | $data = $this->profile; |
|
| 27 | |||
| 28 | 10 | if (!array_key_exists('value', $data) || !is_array($data['value'])) { |
|
| 29 | 6 | return []; |
|
| 30 | } |
||
| 31 | |||
| 32 | 4 | $min = false; |
|
| 33 | 4 | $max = false; |
|
| 34 | |||
| 35 | 4 | foreach ($data['value'] as $key => $item) { |
|
| 36 | 2 | if (is_bool($min) || $item['start'] < $min) { |
|
| 37 | 2 | $min = $item['start']; |
|
| 38 | 2 | } |
|
| 39 | |||
| 40 | 2 | if (array_key_exists('end', $item)) { |
|
| 41 | 2 | if (is_bool($max) || $item['end'] > $max) { |
|
| 42 | 2 | $max = $item['end']; |
|
| 43 | 2 | } |
|
| 44 | 2 | } |
|
| 45 | 4 | } |
|
| 46 | |||
| 47 | 4 | if ($min === 0) { |
|
| 48 | 2 | $min = 1; |
|
| 49 | 2 | } |
|
| 50 | |||
| 51 | |||
| 52 | 4 | if ($max === 0) { |
|
| 53 | $max = 1; |
||
| 54 | } |
||
| 55 | |||
| 56 | |||
| 57 | 4 | foreach ($data['value'] as $key => $item) { |
|
| 58 | 2 | if (!array_key_exists('end', $item)) { |
|
| 59 | $item['end'] = $max; |
||
| 60 | } |
||
| 61 | 2 | $data['value'][$key]['offset'] = floor((($item['start'] - $min) / $min) * 100); |
|
| 62 | 2 | $data['value'][$key]['length'] = floor((($item['end'] - $item['start']) / ($max - $min)) * 100); |
|
| 63 | 4 | } |
|
| 64 | |||
| 65 | 4 | return $data; |
|
| 66 | } |
||
| 67 | |||
| 73 |