Passed
Push — master ( 99a753...df0863 )
by Remco
19:34 queued 09:07
created

CustomerInformation   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Test Coverage

Coverage 57.5%

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 136
ccs 23
cts 40
cp 0.575
rs 10
c 0
b 0
f 0
wmc 14

7 Methods

Rating   Name   Duplication   Size   Complexity  
A set_email_address() 0 2 1
A set_date_of_birth() 0 2 1
A set_gender() 0 11 2
A get_signature_fields() 0 8 2
A get_json() 0 24 6
A set_initials() 0 2 1
A set_telephone_number() 0 2 1
1
<?php
2
/**
3
 * Customer information.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\OmniKassa2
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;
12
13
use DateTime;
14
use InvalidArgumentException;
15
16
/**
17
 * Customer information.
18
 *
19
 * @author  Remco Tolsma
20
 * @version 2.1.0
21
 * @since   2.0.2
22
 */
23
class CustomerInformation {
24
	/**
25
	 * The e-mailadress of the consumer.
26
	 *
27
	 * @var string|null
28
	 */
29
	private $email_address;
30
31
	/**
32
	 * The date of birth of the consumer.
33
	 *
34
	 * @var DateTime|null
35
	 */
36
	private $date_of_birth;
37
38
	/**
39
	 * The gender of the consumer.
40
	 *
41
	 * @var string|null
42
	 */
43
	private $gender;
44
45
	/**
46
	 * The initials of the consumer.
47
	 *
48
	 * @var string|null
49
	 */
50
	private $initials;
51
52
	/**
53
	 * The consumer's telephone number.
54
	 *
55
	 * @var string|null
56
	 */
57
	private $telephone_number;
58
59
	/**
60
	 * Set the e-mailadress of the consumer.
61
	 *
62
	 * @param string|null $email_address E-mailadress of the consumer.
63
	 */
64 1
	public function set_email_address( $email_address ) {
65 1
		$this->email_address = $email_address;
66 1
	}
67
68
	/**
69
	 * Set date of birth.
70
	 *
71
	 * @param DateTime|null $date_of_birth Date of birth.
72
	 */
73 1
	public function set_date_of_birth( DateTime $date_of_birth = null ) {
74 1
		$this->date_of_birth = $date_of_birth;
75 1
	}
76
77
	/**
78
	 * Set gender.
79
	 *
80
	 * @param string|null $gender Gender.
81
	 * @throws InvalidArgumentException Throws invalid argument exception when gender is not null, 'F' or 'M'.
82
	 */
83 1
	public function set_gender( $gender ) {
84 1
		if ( ! in_array( $gender, array( null, 'F', 'M' ), true ) ) {
85
			throw new InvalidArgumentException(
86
				sprintf(
87
					'Gender "%s" must be equal to `null`, "F" or "M".',
88
					$gender
89
				)
90
			);
91
		}
92
93 1
		$this->gender = $gender;
94 1
	}
95
96
	/**
97
	 * Set initials.
98
	 *
99
	 * @param string|null $initials Initials.
100
	 */
101 1
	public function set_initials( $initials ) {
102 1
		$this->initials = $initials;
103 1
	}
104
105
	/**
106
	 * Set telephone number.
107
	 *
108
	 * @param string|null $telephone_number Telephone number.
109
	 */
110 1
	public function set_telephone_number( $telephone_number ) {
111 1
		$this->telephone_number = $telephone_number;
112 1
	}
113
114
	/**
115
	 * Get JSON.
116
	 *
117
	 * @return object
118
	 */
119
	public function get_json() {
120
		$object = (object) array();
121
122
		if ( null !== $this->email_address ) {
123
			$object->emailAddress = $this->email_address;
124
		}
125
126
		if ( null !== $this->date_of_birth ) {
127
			$object->dateOfBirth = $this->date_of_birth->format( 'd-m-Y' );
128
		}
129
130
		if ( null !== $this->gender ) {
131
			$object->gender = $this->gender;
132
		}
133
134
		if ( null !== $this->initials ) {
135
			$object->initials = $this->initials;
136
		}
137
138
		if ( null !== $this->telephone_number ) {
139
			$object->telephoneNumber = $this->telephone_number;
140
		}
141
142
		return $object;
143
	}
144
145
	/**
146
	 * Get signature fields.
147
	 *
148
	 * @param array $fields Fields.
149
	 * @return array
150
	 */
151 1
	public function get_signature_fields( $fields = array() ) {
152 1
		$fields[] = $this->email_address;
153 1
		$fields[] = ( null === $this->date_of_birth ) ? null : $this->date_of_birth->format( 'd-m-Y' );
154 1
		$fields[] = $this->gender;
155 1
		$fields[] = $this->initials;
156 1
		$fields[] = $this->telephone_number;
157
158 1
		return $fields;
159
	}
160
}
161