| Conditions | 14 |
| Total Lines | 23 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 9 | func getRules(number, lastDigit int) map[string]rule { |
||
| 10 | return map[string]rule{ |
||
| 11 | "en": { |
||
| 12 | Single: number == 1, |
||
| 13 | Plural: number > 1 || number == 0, |
||
| 14 | }, |
||
| 15 | "ru": { |
||
| 16 | Special: (number >= 5 && number <= 20) || lastDigit == 0 || (lastDigit >= 5 && lastDigit <= 9), |
||
| 17 | Single: lastDigit == 1, |
||
| 18 | Plural: lastDigit >= 2 && lastDigit < 5, |
||
| 19 | }, |
||
| 20 | "uk": { |
||
| 21 | Special: (number >= 5 && number <= 20) || lastDigit == 0 || (lastDigit >= 5 && lastDigit <= 9), |
||
| 22 | Single: lastDigit == 1, |
||
| 23 | Plural: lastDigit >= 2 && lastDigit < 5, |
||
| 24 | }, |
||
| 25 | "nl": { |
||
| 26 | Single: number == 1, |
||
| 27 | Plural: number > 1 || number == 0, |
||
| 28 | }, |
||
| 29 | "de": { |
||
| 30 | Single: number == 1, |
||
| 31 | Plural: number > 1 || number == 0, |
||
| 32 | }, |
||
| 35 |