AmountTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 13 2
1
<?php
2
/**
3
 * Amount 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\Money\Money;
15
16
/**
17
 * Amount transformer
18
 *
19
 * @author  Reüel van der Steege
20
 * @version 1.0.0
21
 * @since   1.0.0
22
 */
23
class AmountTransformer {
24
	/**
25
	 * Transform Pronamic money to Adyen amount.
26
	 *
27
	 * @param Money $money Pronamic money to convert.
28
	 * @return Amount
29
	 * @throws InvalidArgumentException Throws invalid argument exception when WordPress money object does not contain a currency with an alphabetic code.
30
	 */
31 2
	public static function transform( Money $money ) {
32 2
		$currency = $money->get_currency()->get_alphabetic_code();
33
34 2
		if ( null === $currency ) {
35 1
			throw new InvalidArgumentException( 'Can not transform WordPress money object to Adyen amount object due to empty currency code.' );
36
		}
37
38 1
		$amount = new Amount(
39 1
			$currency,
40 1
			$money->get_minor_units()
41
		);
42
43 1
		return $amount;
44
	}
45
}
46