| Conditions | 10 |
| Total Lines | 22 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 1 |
| CRAP Score | 10 |
| 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 | Single: lastDigit == 1 || number == 0, |
||
| 13 | Plural: lastDigit >= 2 && lastDigit < 5, |
||
| 14 | Special: []bool{ |
||
| 15 | number >= 5 && number <= 20, |
||
| 16 | lastDigit == 0, |
||
| 17 | lastDigit >= 5 && lastDigit <= 9, |
||
| 18 | }, |
||
| 19 | }, |
||
| 20 | "uk": { |
||
| 21 | Single: lastDigit == 1 || number == 0, |
||
| 22 | Plural: lastDigit >= 2 && lastDigit < 5, |
||
| 23 | Special: []bool{ |
||
| 24 | number >= 5 && number <= 20, |
||
| 25 | lastDigit == 0, |
||
| 26 | lastDigit >= 5 && lastDigit <= 9, |
||
| 27 | }, |
||
| 31 |