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 0
Metric Value
cc 1
c 0
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.donationFormContent.paymentType === PAYMENT_TYPE_DEBIT_VALUE &&
9
			state.donationInputValidation.paymentType.isValid === true &&
10
			state.validity.bankData === true
11
		);
12
	},
13
	hasOtherValidPayment = function ( state ) {
14
		return (
15
			state.donationFormContent.paymentType !== PAYMENT_TYPE_DEBIT_VALUE &&
16
			state.donationInputValidation.paymentType.isValid === true
17
		);
18
	}
19
;
20
21
module.exports = function ( state ) {
22
	var result = _.clone( validationResult ),
23
		respectiveValidators = _.pick( state.donationInputValidation, [ 'paymentType', 'iban', 'bic', 'accountNumber', 'bankCode' ] )
24
	;
25
26
	result.dataEntered = _.contains( _.pluck( respectiveValidators, 'dataEntered' ), true );
27
28
	if ( hasValidDirectDebitPayment( state ) || hasOtherValidPayment( state ) ) {
29
		result.isValid = true;
30
	}
31
	else if ( !_.contains( _.pluck( respectiveValidators, 'isValid' ), false ) ) {
32
		result.isValid = null;
33
	}
34
	else {
35
		result.isValid = false;
36
	}
37
38
	return result;
39
};
40