Failed Conditions
Push — master ( c5b7ba...a5775d )
by Reüel
11:08 queued 03:48
created

AmountTransformer::transform()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 7
cts 8
cp 0.875
crap 2.0078
rs 10
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\Mollie
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
12
13
use Pronamic\WordPress\Money\Money;
14
15
/**
16
 * Amount transformer
17
 *
18
 * @author  Reüel van der Steege
19
 * @version 2.1.0
20
 * @since   2.1.0
21
 */
22
class AmountTransformer {
23
	/**
24
	 * Transform Pronamic money to Mollie amount.
25
	 *
26
	 * @param Money $money Pronamic money to convert.
27
	 * @return Amount
28
	 * @throws \InvalidArgumentException Throws exception on invalid alphabetic currency code in given money object.
29
	 */
30 2
	public static function transform( Money $money ) {
31 2
		$alphabetic_code = $money->get_currency()->get_alphabetic_code();
32
33 2
		if ( null === $alphabetic_code ) {
34
			throw new \InvalidArgumentException( 'Alphabetic currency code is required to transform money to Mollie amount object.' );
35
		}
36
37 2
		$amount = new Amount(
38 2
			\strval( $alphabetic_code ),
39 2
			$money->format()
40
		);
41
42 2
		return $amount;
43
	}
44
}
45