Passed
Push — feature/post-pay ( 50af39...9c8201 )
by Remco
05:53
created

CustomerInformation::set_gender()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
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.0.2
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( 'Gender "%s" must be equal to `null`, "F" or "M".' );
86
		}
87
88 1
		$this->gender = $gender;
89 1
	}
90
91
	/**
92
	 * Set initials.
93
	 *
94
	 * @param string|null $initials Initials.
95
	 */
96 1
	public function set_initials( $initials ) {
97 1
		$this->initials = $initials;
98 1
	}
99
100
	/**
101
	 * Set telephone number.
102
	 *
103
	 * @param string|null $telephone_number Telephone number.
104
	 */
105 1
	public function set_telephone_number( $telephone_number ) {
106 1
		$this->telephone_number = $telephone_number;
107 1
	}
108
109
	/**
110
	 * Get JSON.
111
	 *
112
	 * @return object
113
	 */
114
	public function get_json() {
115
		$object = (object) array();
116
117
		if ( null !== $this->email_address ) {
118
			$object->emailAddress = $this->email_address;
119
		}
120
121
		if ( null !== $this->date_of_birth ) {
122
			$object->dateOfBirth = $this->date_of_birth->format( 'd-m-Y' );
123
		}
124
125
		if ( null !== $this->gender ) {
126
			$object->gender = $this->gender;
127
		}
128
129
		if ( null !== $this->initials ) {
130
			$object->initials = $this->initials;
131
		}
132
133
		if ( null !== $this->telephone_number ) {
134
			$object->telephoneNumber = $this->telephone_number;
135
		}
136
137
		return $object;
138
	}
139
140
	/**
141
	 * Get signature fields.
142
	 *
143
	 * @param array $fields Fields.
144
	 * @return array
145
	 */
146 1
	public function get_signature_fields( $fields = array() ) {
147 1
		$fields[] = $this->email_address;
148 1
		$fields[] = ( null === $this->date_of_birth ) ? null : $this->date_of_birth->format( 'd-m-Y' );
149 1
		$fields[] = $this->gender;
150 1
		$fields[] = $this->initials;
151 1
		$fields[] = $this->telephone_number;
152
153 1
		return $fields;
154
	}
155
}
156