Failed Conditions
Push — develop ( 8c1843...7824fe )
by Reüel
07:49
created

src/AddressTransformer.php (1 issue)

Labels
Severity
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
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