Test Failed
Push — develop ( 64bec5...308757 )
by Remco
03:59
created

Customer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * Mollie customer.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
12
13
/**
14
 * Mollie customer
15
 *
16
 * @link    https://docs.mollie.com/reference/v2/customers-api/create-customer
17
 * @author  Remco Tolsma
18
 * @version 3.0.0
19
 * @since   3.0.0
20
 */
21
class Customer {
22
	/**
23
	 * ID.
24
	 *
25
	 * @var string|null
26
	 */
27
	private $id;
28
29
	/**
30
	 * Mode.
31
	 *
32
	 * @var string|null
33
	 */
34
	private $mode;
35
36
	/**
37
	 * Name.
38
	 *
39
	 * @var string|null
40
	 */
41
	private $name;
42
43
	/**
44
	 * Email.
45
	 *
46
	 * @var string|null
47
	 */
48
	private $email;
49
50
	/**
51
	 * Locale.
52
	 *
53
	 * @var string
54
	 */
55
	public $locale;
56
57
	/**
58
	 * Construct Mollie customer.
59
	 *
60
	 * @param string|null $id Mollie customer ID.
61
	 */
62
	public function __construct( $id = null ) {
63
		$this->set_id( $id );
64
	}
65
66
	/**
67
	 * Get ID.
68
	 *
69
	 * @return string|null
70
	 */
71
	public function get_id() {
72
		return $this->id;
73
	}
74
75
	/**
76
	 * Set ID.
77
	 *
78
	 * @param string|null $id ID.
79
	 */
80
	public function set_id( $id ) {
81
		$this->id = $id;
82
	}
83
84
	/**
85
	 * Get mode.
86
	 *
87
	 * @return string|null
88
	 */
89
	public function get_mode() {
90
		return $this->mode;
91
	}
92
93
	/**
94
	 * Set mode.
95
	 *
96
	 * @param string|null $mode Mode.
97
	 */
98
	public function set_mode( $mode ) {
99
		$this->mode = $mode;
100
	}
101
102
	/**
103
	 * Get name.
104
	 *
105
	 * @return string|null
106
	 */
107
	public function get_name() {
108
		return $this->name;
109
	}
110
111
	/**
112
	 * Set name.
113
	 *
114
	 * @param string|null $name Name.
115
	 */
116
	public function set_name( $name ) {
117
		$this->name = $name;
118
	}
119
120
	/**
121
	 * Get email.
122
	 *
123
	 * @return string|null
124
	 */
125
	public function get_email() {
126
		return $this->email;
127
	}
128
129
	/**
130
	 * Set email.
131
	 *
132
	 * @param string|null $email Email.
133
	 */
134
	public function set_email( $email ) {
135
		$this->email = $email;
136
	}
137
138
	/**
139
	 * Get locale.
140
	 *
141
	 * @return string|null
142
	 */
143
	public function get_locale() {
144
		return $this->locale;
145
	}
146
147
	/**
148
	 * Set locale.
149
	 *
150
	 * @param string|null $locale Locale.
151
	 */
152
	public function set_locale( $locale ) {
153
		$this->locale = $locale;
154
	}
155
156
	/**
157
	 * Get array.
158
	 *
159
	 * @return array
160
	 */
161
	public function get_array() {
162
		$array = array(
163
			'name'   => $this->get_name(),
164
			'email'  => $this->get_email(),
165
			'locale' => $this->get_locale(),
166
		);
167
168
		/*
169
		 * Array filter will remove values NULL, FALSE and empty strings ('')
170
		 */
171
		$array = array_filter( $array );
172
173
		return $array;
174
	}
175
176
	/**
177
	 * Create customer from object.
178
	 *
179
	 * @param object $object Object.
180
	 * @return Customer
181
	 */
182
	public static function from_object( $object ) {
183
		$customer = new self();
184
185
		if ( property_exists( $object, 'id' ) ) {
186
			$customer->set_id( $object->id );
187
		}
188
189
		if ( property_exists( $object, 'mode' ) ) {
190
			$customer->set_mode( $object->mode );
191
		}
192
193
		if ( property_exists( $object, 'name' ) ) {
194
			$customer->set_name( $object->name );
195
		}
196
197
		if ( property_exists( $object, 'email' ) ) {
198
			$customer->set_email( $object->email );
199
		}
200
201
		if ( property_exists( $object, 'locale' ) ) {
202
			$customer->set_locale( $object->locale );
203
		}
204
205
		return $customer;
206
	}
207
}
208