formio/node_modules/moment/src/locale/sl.js   F
last analyzed

Complexity

Total Complexity 99
Complexity/F 33

Size

Lines of Code 160
Function Count 3

Duplication

Duplicated Lines 160
Ratio 100 %

Importance

Changes 0
Metric Value
cc 0
wmc 99
nc 1
mnd 5
bc 26
fnc 3
dl 160
loc 160
rs 1.5789
bpm 8.6666
cpm 33
noi 6
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
B moment.defineLocale(ꞌslꞌ).calendar.lastWeek 15 15 8
B moment.defineLocale(ꞌslꞌ).calendar.nextWeek 15 15 8
D sl.js ➔ processRelativeTime 81 81 83

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complexity

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like formio/node_modules/moment/src/locale/sl.js 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
2
//! locale : Slovenian [sl]
3
//! author : Robert Sedovšek : https://github.com/sedovsek
4
5 View Code Duplication
import moment from '../moment';
6
7
function processRelativeTime(number, withoutSuffix, key, isFuture) {
8
    var result = number + ' ';
9
    switch (key) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
10
        case 's':
11
            return withoutSuffix || isFuture ? 'nekaj sekund' : 'nekaj sekundami';
12
        case 'ss':
13
            if (number === 1) {
14
                result += withoutSuffix ? 'sekundo' : 'sekundi';
15
            } else if (number === 2) {
16
                result += withoutSuffix || isFuture ? 'sekundi' : 'sekundah';
17
            } else if (number < 5) {
18
                result += withoutSuffix || isFuture ? 'sekunde' : 'sekundah';
19
            } else {
20
                result += withoutSuffix || isFuture ? 'sekund' : 'sekund';
21
            }
22
            return result;
23
        case 'm':
24
            return withoutSuffix ? 'ena minuta' : 'eno minuto';
25
        case 'mm':
26
            if (number === 1) {
27
                result += withoutSuffix ? 'minuta' : 'minuto';
28
            } else if (number === 2) {
29
                result += withoutSuffix || isFuture ? 'minuti' : 'minutama';
30
            } else if (number < 5) {
31
                result += withoutSuffix || isFuture ? 'minute' : 'minutami';
32
            } else {
33
                result += withoutSuffix || isFuture ? 'minut' : 'minutami';
34
            }
35
            return result;
36
        case 'h':
37
            return withoutSuffix ? 'ena ura' : 'eno uro';
38
        case 'hh':
39
            if (number === 1) {
40
                result += withoutSuffix ? 'ura' : 'uro';
41
            } else if (number === 2) {
42
                result += withoutSuffix || isFuture ? 'uri' : 'urama';
43
            } else if (number < 5) {
44
                result += withoutSuffix || isFuture ? 'ure' : 'urami';
45
            } else {
46
                result += withoutSuffix || isFuture ? 'ur' : 'urami';
47
            }
48
            return result;
49
        case 'd':
50
            return withoutSuffix || isFuture ? 'en dan' : 'enim dnem';
51
        case 'dd':
52
            if (number === 1) {
53
                result += withoutSuffix || isFuture ? 'dan' : 'dnem';
54
            } else if (number === 2) {
55
                result += withoutSuffix || isFuture ? 'dni' : 'dnevoma';
56
            } else {
57
                result += withoutSuffix || isFuture ? 'dni' : 'dnevi';
58
            }
59
            return result;
60
        case 'M':
61
            return withoutSuffix || isFuture ? 'en mesec' : 'enim mesecem';
62
        case 'MM':
63
            if (number === 1) {
64
                result += withoutSuffix || isFuture ? 'mesec' : 'mesecem';
65
            } else if (number === 2) {
66
                result += withoutSuffix || isFuture ? 'meseca' : 'mesecema';
67
            } else if (number < 5) {
68
                result += withoutSuffix || isFuture ? 'mesece' : 'meseci';
69
            } else {
70
                result += withoutSuffix || isFuture ? 'mesecev' : 'meseci';
71
            }
72
            return result;
73
        case 'y':
74
            return withoutSuffix || isFuture ? 'eno leto' : 'enim letom';
75
        case 'yy':
76
            if (number === 1) {
77
                result += withoutSuffix || isFuture ? 'leto' : 'letom';
78
            } else if (number === 2) {
79
                result += withoutSuffix || isFuture ? 'leti' : 'letoma';
80
            } else if (number < 5) {
81
                result += withoutSuffix || isFuture ? 'leta' : 'leti';
82
            } else {
83
                result += withoutSuffix || isFuture ? 'let' : 'leti';
84
            }
85
            return result;
86
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
87
}
88
89
export default moment.defineLocale('sl', {
90
    months : 'januar_februar_marec_april_maj_junij_julij_avgust_september_oktober_november_december'.split('_'),
91
    monthsShort : 'jan._feb._mar._apr._maj._jun._jul._avg._sep._okt._nov._dec.'.split('_'),
92
    monthsParseExact: true,
93
    weekdays : 'nedelja_ponedeljek_torek_sreda_četrtek_petek_sobota'.split('_'),
94
    weekdaysShort : 'ned._pon._tor._sre._čet._pet._sob.'.split('_'),
95
    weekdaysMin : 'ne_po_to_sr_če_pe_so'.split('_'),
96
    weekdaysParseExact : true,
97
    longDateFormat : {
98
        LT : 'H:mm',
99
        LTS : 'H:mm:ss',
100
        L : 'DD.MM.YYYY',
101
        LL : 'D. MMMM YYYY',
102
        LLL : 'D. MMMM YYYY H:mm',
103
        LLLL : 'dddd, D. MMMM YYYY H:mm'
104
    },
105
    calendar : {
106
        sameDay  : '[danes ob] LT',
107
        nextDay  : '[jutri ob] LT',
108
109
        nextWeek : function () {
110
            switch (this.day()) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
111
                case 0:
112
                    return '[v] [nedeljo] [ob] LT';
113
                case 3:
114
                    return '[v] [sredo] [ob] LT';
115
                case 6:
116
                    return '[v] [soboto] [ob] LT';
117
                case 1:
118
                case 2:
119
                case 4:
120
                case 5:
121
                    return '[v] dddd [ob] LT';
122
            }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
123
        },
124
        lastDay  : '[včeraj ob] LT',
125
        lastWeek : function () {
126
            switch (this.day()) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
127
                case 0:
128
                    return '[prejšnjo] [nedeljo] [ob] LT';
129
                case 3:
130
                    return '[prejšnjo] [sredo] [ob] LT';
131
                case 6:
132
                    return '[prejšnjo] [soboto] [ob] LT';
133
                case 1:
134
                case 2:
135
                case 4:
136
                case 5:
137
                    return '[prejšnji] dddd [ob] LT';
138
            }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
139
        },
140
        sameElse : 'L'
141
    },
142
    relativeTime : {
143
        future : 'čez %s',
144
        past   : 'pred %s',
145
        s      : processRelativeTime,
146
        ss     : processRelativeTime,
147
        m      : processRelativeTime,
148
        mm     : processRelativeTime,
149
        h      : processRelativeTime,
150
        hh     : processRelativeTime,
151
        d      : processRelativeTime,
152
        dd     : processRelativeTime,
153
        M      : processRelativeTime,
154
        MM     : processRelativeTime,
155
        y      : processRelativeTime,
156
        yy     : processRelativeTime
157
    },
158
    dayOfMonthOrdinalParse: /\d{1,2}\./,
159
    ordinal : '%d.',
160
    week : {
161
        dow : 1, // Monday is the first day of the week.
162
        doy : 7  // The week that contains Jan 1st is the first week of the year.
163
    }
164
});
165