Failed Conditions
Push — develop ( 2de1b1...49fae7 )
by Remco
12:57 queued 04:10
created

Util::transform_flat_response()   B

Complexity

Conditions 8
Paths 2

Size

Total Lines 38
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 17
nc 2
nop 1
dl 0
loc 38
ccs 18
cts 18
cp 1
crap 8
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Buckaroo;
4
5
use Pronamic\WordPress\Pay\Payments\Payment;
6
7
/**
8
 * Title: Buckaroo utility class
9
 * Description:
10
 * Copyright: 2005-2021 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author Remco Tolsma
14
 * @version 2.0.0
15
 * @since 1.0.0
16
 */
17
class Util {
18
	/**
19
	 * Get invoice number.
20
	 *
21
	 * @param string $invoice_number
22
	 * @param Payment $payment
23
	 *
24
	 * @return string
25
	 */
26
	public static function get_invoice_number( $invoice_number, Payment $payment ) {
27
		// Replacements definition
28
		$replacements = array(
29
			'{order_id}'   => $payment->get_order_id(),
30
			'{payment_id}' => $payment->get_id(),
31
		);
32
33
		// Find and replace
34
		$invoice_number = str_replace(
35
			array_keys( $replacements ),
36
			array_values( $replacements ),
37
			$invoice_number,
38
			$count
39
		);
40
41
		// Make sure there is an dynamic part in the order ID
42
		if ( 0 === $count ) {
43
			$invoice_number .= $payment->get_id();
44
		}
45
46
		return $invoice_number;
47
	}
48
}
49