| Conditions | 72 |
| Paths | 93 |
| Total Lines | 70 |
| 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:
Complex classes like sl.js ➔ ... ➔ processRelativeTime 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 | //! moment.js locale configuration |
||
| 13 | function processRelativeTime(number, withoutSuffix, key, isFuture) { |
||
| 14 | var result = number + ' '; |
||
| 15 | switch (key) { |
||
|
1 ignored issue
–
show
|
|||
| 16 | case 's': |
||
| 17 | return withoutSuffix || isFuture ? 'nekaj sekund' : 'nekaj sekundami'; |
||
| 18 | case 'm': |
||
| 19 | return withoutSuffix ? 'ena minuta' : 'eno minuto'; |
||
| 20 | case 'mm': |
||
| 21 | if (number === 1) { |
||
| 22 | result += withoutSuffix ? 'minuta' : 'minuto'; |
||
| 23 | } else if (number === 2) { |
||
| 24 | result += withoutSuffix || isFuture ? 'minuti' : 'minutama'; |
||
| 25 | } else if (number < 5) { |
||
| 26 | result += withoutSuffix || isFuture ? 'minute' : 'minutami'; |
||
| 27 | } else { |
||
| 28 | result += withoutSuffix || isFuture ? 'minut' : 'minutami'; |
||
| 29 | } |
||
| 30 | return result; |
||
| 31 | case 'h': |
||
| 32 | return withoutSuffix ? 'ena ura' : 'eno uro'; |
||
| 33 | case 'hh': |
||
| 34 | if (number === 1) { |
||
| 35 | result += withoutSuffix ? 'ura' : 'uro'; |
||
| 36 | } else if (number === 2) { |
||
| 37 | result += withoutSuffix || isFuture ? 'uri' : 'urama'; |
||
| 38 | } else if (number < 5) { |
||
| 39 | result += withoutSuffix || isFuture ? 'ure' : 'urami'; |
||
| 40 | } else { |
||
| 41 | result += withoutSuffix || isFuture ? 'ur' : 'urami'; |
||
| 42 | } |
||
| 43 | return result; |
||
| 44 | case 'd': |
||
| 45 | return withoutSuffix || isFuture ? 'en dan' : 'enim dnem'; |
||
| 46 | case 'dd': |
||
| 47 | if (number === 1) { |
||
| 48 | result += withoutSuffix || isFuture ? 'dan' : 'dnem'; |
||
| 49 | } else if (number === 2) { |
||
| 50 | result += withoutSuffix || isFuture ? 'dni' : 'dnevoma'; |
||
| 51 | } else { |
||
| 52 | result += withoutSuffix || isFuture ? 'dni' : 'dnevi'; |
||
| 53 | } |
||
| 54 | return result; |
||
| 55 | case 'M': |
||
| 56 | return withoutSuffix || isFuture ? 'en mesec' : 'enim mesecem'; |
||
| 57 | case 'MM': |
||
| 58 | if (number === 1) { |
||
| 59 | result += withoutSuffix || isFuture ? 'mesec' : 'mesecem'; |
||
| 60 | } else if (number === 2) { |
||
| 61 | result += withoutSuffix || isFuture ? 'meseca' : 'mesecema'; |
||
| 62 | } else if (number < 5) { |
||
| 63 | result += withoutSuffix || isFuture ? 'mesece' : 'meseci'; |
||
| 64 | } else { |
||
| 65 | result += withoutSuffix || isFuture ? 'mesecev' : 'meseci'; |
||
| 66 | } |
||
| 67 | return result; |
||
| 68 | case 'y': |
||
| 69 | return withoutSuffix || isFuture ? 'eno leto' : 'enim letom'; |
||
| 70 | case 'yy': |
||
| 71 | if (number === 1) { |
||
| 72 | result += withoutSuffix || isFuture ? 'leto' : 'letom'; |
||
| 73 | } else if (number === 2) { |
||
| 74 | result += withoutSuffix || isFuture ? 'leti' : 'letoma'; |
||
| 75 | } else if (number < 5) { |
||
| 76 | result += withoutSuffix || isFuture ? 'leta' : 'leti'; |
||
| 77 | } else { |
||
| 78 | result += withoutSuffix || isFuture ? 'let' : 'leti'; |
||
| 79 | } |
||
| 80 | return result; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 162 | })); |