Passed
Push — master ( b8e26c...2f113f )
by Remco
05:42
created

Address::get_json()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 0
dl 0
loc 20
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * Address
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 InvalidArgumentException;
14
use stdClass;
15
use JsonSchema\Constraints\Constraint;
16
use JsonSchema\Exception\ValidationException;
17
use JsonSchema\Validator;
18
19
/**
20
 * Address
21
 *
22
 * @author  Remco Tolsma
23
 * @version 2.0.2
24
 * @since   2.0.2
25
 */
26
class Address {
27
	/**
28
	 * First name.
29
	 *
30
	 * @var string
31
	 */
32
	private $first_name;
33
34
	/**
35
	 * Insert or second name.
36
	 *
37
	 * @var string
38
	 */
39
	private $middle_name;
40
41
	/**
42
	 * Surname.
43
	 *
44
	 * @var string
45
	 */
46
	private $last_name;
47
48
	/**
49
	 * Street.
50
	 *
51
	 * Note: In case of payment via Visa, Mastercard, V PAY,
52
	 * Bancontact and Maestro the street name will be
53
	 * truncated to 50 characters.
54
	 *
55
	 * @var string
56
	 */
57
	private $street;
58
59
	/**
60
	 * House number.
61
	 *
62
	 * Note: In case of payment via Visa, Mastercard, V PAY,
63
	 * Bancontact and Maestro the houseNumber concatenated
64
	 * with houseNumberAddition (see below) will be
65
	 * truncated to 10 characters.
66
	 *
67
	 * @var string
68
	 */
69
	private $house_number;
70
71
	/**
72
	 * House number additions.
73
	 *
74
	 * @var string
75
	 */
76
	private $house_number_addition;
77
78
	/**
79
	 * Postal code.
80
	 *
81
	 * @var string
82
	 */
83
	private $postal_code;
84
85
	/**
86
	 * City.
87
	 *
88
	 * @var string
89
	 */
90
	private $city;
91
92
	/**
93
	 * Country code, ISO 3166-1 alpha-2.
94
	 *
95
	 * @var string
96
	 */
97
	private $country_code;
98
99
	/**
100
	 * Get JSON.
101
	 *
102
	 * @return object
103
	 */
104
	public function get_json() {
105
		$data = array(
106
			'firstName'           => $this->first_name,
107
			'middleName'          => $this->middle_name,
108
			'lastName'            => $this->last_name,
109
			'street'              => $this->street,
110
			'houseNumber'         => $this->house_number,
111
			'houseNumberAddition' => $this->house_number_addition,
112
			'postalCode'          => $this->postal_code,
113
			'city'                => $this->city,
114
			'countryCode'         => $this->country_code,
115
		);
116
117
		$data = array_filter( $data );
118
119
		if ( empty( $data ) ) {
120
			return null;
121
		}
122
123
		return (object) $data;
124
	}
125
}
126