Completed
Push — master ( ebbfd2...019445 )
by Jeroen De
62:46
created

module.exports   C

Complexity

Conditions 11
Paths 8

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 11
nc 8
nop 2
dl 0
loc 24
rs 5.3305
c 2
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like module.exports 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
'use strict';
2
3
module.exports = function ( state, action ) {
4
	if ( typeof state === 'undefined' ) {
5
		state = { isValidating: false, runningValidations: 0 };
6
	}
7
	switch ( action.type ) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
8
		case 'BEGIN_BANK_DATA_VALIDATION':
9
		case 'BEGIN_EMAIL_ADDRESS_VALIDATION':
10
		case 'BEGIN_ADDRESS_VALIDATION':
11
		case 'BEGIN_PAYMENT_DATA_VALIDATION':
12
			return { isValidating: true, runningValidations: state.runningValidations + 1 };
13
		case 'FINISH_BANK_DATA_VALIDATION':
14
		case 'FINISH_EMAIL_ADDRESS_VALIDATION':
15
		case 'FINISH_ADDRESS_VALIDATION':
16
		case 'FINISH_PAYMENT_DATA_VALIDATION':
17
			if ( state.runningValidations === 0 ) {
18
				return state;
19
			}
20
			return {
21
				isValidating: state.runningValidations > 1,
22
				runningValidations: state.runningValidations - 1
23
			};
24
	}
25
	return state;
26
};
27