AddressTransformer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 22
c 3
b 0
f 0
dl 0
loc 42
ccs 20
cts 20
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 35 5
1
<?php
2
/**
3
 * Address transformer
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
use InvalidArgumentException;
14
use Pronamic\WordPress\Pay\Address as Pay_Address;
15
16
/**
17
 * Address transformer
18
 *
19
 * @author  Remco Tolsma
20
 * @version 1.0.0
21
 * @since   1.0.0
22
 */
23
class AddressTransformer {
24
	/**
25
	 * Transform WordPress Pay address to Adyen address.
26
	 *
27
	 * @param Pay_Address $address WordPress Pay address to convert.
28
	 * @return Address|null
29
	 */
30 5
	public static function transform( Pay_Address $address ) {
31 5
		$country = $address->get_country();
32
33 5
		if ( null === $country ) {
34 1
			return null;
35
		}
36
37 4
		$country_code = $country->get_code();
38
39 4
		if ( null === $country_code ) {
40 1
			return null;
41
		}
42
43 3
		$state_or_province = null;
44
45 3
		$region = $address->get_region();
46
47 3
		if ( null !== $region ) {
48 1
			$state_or_province = $region->get_code();
49
		}
50
51
		try {
52 3
			$address = new Address(
53 3
				$country_code,
54 3
				$address->get_street_name(),
55 3
				(string) $address->get_house_number(),
56 3
				$address->get_postal_code(),
57 3
				$address->get_city(),
58
				$state_or_province
59
			);
60 1
		} catch ( InvalidArgumentException $exception ) {
61 1
			return null;
62
		}
63
64 2
		return $address;
65
	}
66
}
67