| Conditions | 14 |
| Total Lines | 15 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 1 |
| CRAP Score | 14 |
| Changes | 0 | ||
Complex classes like timeago.getRules often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | package timeago |
||
| 5 | func getRules(number, lastDigit int) map[string]models.Rule { |
||
| 6 | 1 | return map[string]models.Rule{ |
|
| 7 | "en": { |
||
| 8 | Single: number == 1, |
||
| 9 | Plural: number > 1 || number == 0, |
||
| 10 | }, |
||
| 11 | "ru": { |
||
| 12 | Special: (number >= 5 && number <= 20) || lastDigit == 0 || (lastDigit >= 5 && lastDigit <= 9), |
||
| 13 | Single: lastDigit == 1 || number == 0, |
||
| 14 | Plural: lastDigit >= 2 && lastDigit < 5, |
||
| 15 | }, |
||
| 16 | "uk": { |
||
| 17 | Special: (number >= 5 && number <= 20) || lastDigit == 0 || (lastDigit >= 5 && lastDigit <= 9), |
||
| 18 | Single: lastDigit == 1 || number == 0, |
||
| 19 | Plural: lastDigit >= 2 && lastDigit < 5, |
||
| 20 | }, |
||
| 23 |