Completed
Push — master ( 9b13ee...06d762 )
by wiese
106:46 queued 41:44
created

  A

Complexity

Conditions 1
Paths 2

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
dl 6
loc 6
rs 9.4285
nop 1
1 View Code Duplication
'use strict';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
3
var _ = require( 'underscore' ),
4
	validationResult = require( './../validation_result' ),
5
	PAYMENT_TYPE_DEBIT_VALUE = 'BEZ',
6
	hasValidDirectDebitPayment = function ( state ) {
7
		return (
8
			state.membershipFormContent.paymentType === PAYMENT_TYPE_DEBIT_VALUE &&
9
			state.validity.bankData === true
10
		);
11
	},
12
	hasOtherValidPayment = function ( state ) {
13
		return (
14
			state.membershipFormContent.paymentType !== PAYMENT_TYPE_DEBIT_VALUE &&
15
			state.membershipFormContent.paymentType !== null
16
		);
17
	}
18
;
19
20
module.exports = function ( state ) {
21
	var result = _.clone( validationResult ),
22
		respectiveValidators = _.pick( state.membershipInputValidation, [ 'iban', 'bic', 'accountNumber', 'bankCode' ] )
23
	;
24
25
	result.dataEntered = state.membershipFormContent.paymentType !== null || _.contains( _.pluck( respectiveValidators, 'dataEntered' ), true );
26
27
	if ( hasValidDirectDebitPayment( state ) || hasOtherValidPayment( state ) ) {
28
		result.isValid = true;
29
	}
30
	else if ( !_.contains( _.pluck( respectiveValidators, 'isValid' ), false ) ) {
31
		result.isValid = null;
32
	}
33
	else {
34
		result.isValid = false;
35
	}
36
37
	return result;
38
};
39