Failed Conditions
Push — develop ( 6b2398...9887e4 )
by Remco
03:45 queued 28s
created

AddressTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 42
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0
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-2019 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 Pronamic\WordPress\Pay\Address as Pay_Address;
14
15
/**
16
 * Address transformer
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.0.0
20
 * @since   1.0.0
21
 */
22
class AddressTransformer {
23
	/**
24
	 * Transform WordPress Pay address to Adyen address.
25
	 *
26
	 * @param Pay_Address $address WordPress Pay address to convert.
27
	 * @return Address|null
28
	 */
29
	public static function transform( Pay_Address $address ) {
30
		$country = $address->get_country();
31
32
		if ( null === $country ) {
33
			return null;
34
		}
35
36
		$country_code = $country->get_code();
37
38
		if ( null === $country_code ) {
39
			return null;
40
		}
41
42
		$state_or_province = null;
43
44
		$region = $address->get_region();
45
46
		if ( null !== $region ) {
47
			$state_or_province = $region->get_code();
48
		}
49
50
		try {
51
			$address = new Address(
52
				$country_code,
53
				$address->get_street_name(),
54
				strval( $address->get_house_number() ),
55
				$address->get_postal_code(),
56
				$address->get_city(),
57
				$state_or_province
58
			);
59
		} catch ( InvalidArgumentException $exception ) {
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\G...nvalidArgumentException was not found. Did you mean InvalidArgumentException? If so, make sure to prefix the type with \.
Loading history...
60
			return null;
61
		}
62
63
		return $address;
64
	}
65
}
66