AmountTransformer   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 13 1
1
<?php
2
/**
3
 * Amount transformer.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2022 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
		$amount = new Amount(
32 2
			$money->get_currency()->get_alphabetic_code(),
33
			/**
34
			 * Make sure to send the right amount of decimals and omit the
35
			 * thousands separator. Non-string values are not accepted.
36
			 * 
37
			 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
38
			 */
39 2
			$money->number_format( null, '.', '' )
40
		);
41
42 2
		return $amount;
43
	}
44
}
45