CLI   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 25
c 2
b 0
f 0
dl 0
loc 76
ccs 0
cts 36
cp 0
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 25 2
A wp_cli_transaction_refund_info() 0 7 2
A wp_cli_transaction_status() 0 7 2
1
<?php
2
/**
3
 * CLI
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2022 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Buckaroo
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Buckaroo;
12
13
/**
14
 * Title: CLI
15
 * Description:
16
 * Copyright: 2005-2022 Pronamic
17
 * Company: Pronamic
18
 *
19
 * @author  Remco Tolsma
20
 * @version 2.1.0
21
 * @since   2.1.0
22
 * @link    https://github.com/woocommerce/woocommerce/blob/3.9.0/includes/class-wc-cli.php
23
 */
24
class CLI {
25
	/**
26
	 * Gateway integration.
27
	 *
28
	 * @var Integration
29
	 */
30
	private $integration;
31
32
	/**
33
	 * Construct CLI.
34
	 *
35
	 * @param Integration $integration Integration.
36
	 * @retrun void
37
	 */
38
	public function __construct( $integration ) {
39
		$this->integration = $integration;
40
41
		// Check WP-CLI.
42
		if ( ! \class_exists( '\WP_CLI' ) ) {
43
			return;
44
		}
45
46
		\WP_CLI::add_command(
47
			'pronamic-pay buckaroo transaction status',
48
			function( $args, $assoc_args ) {
49
				$this->wp_cli_transaction_status( $args, $assoc_args );
50
			},
51
			array(
52
				'shortdesc' => 'This returns the status for the provided transaction',
53
			)
54
		);
55
56
		\WP_CLI::add_command(
57
			'pronamic-pay buckaroo transaction refund-info',
58
			function( $args, $assoc_args ) {
59
				$this->wp_cli_transaction_refund_info( $args, $assoc_args );
60
			},
61
			array(
62
				'shortdesc' => 'This returns the refund info',
63
			)
64
		);
65
	}
66
67
	/**
68
	 * CLI transaction status.
69
	 *
70
	 * @link https://testcheckout.buckaroo.nl/json/Docs/Api/GET-json-Transaction-Status-transactionKey
71
	 * @param array<string> $args       Arguments.
72
	 * @param array<string> $assoc_args Associative arguments.
73
	 * @return void
74
	 */
75
	public function wp_cli_transaction_status( $args, $assoc_args ) {
76
		$gateway = $this->integration->get_gateway( (int) $assoc_args['config_id'] );
77
78
		foreach ( $args as $transaction_key ) {
79
			$result = $gateway->request( 'GET', 'Transaction/Status/' . $transaction_key );
80
81
			\WP_CLI::line( \wp_json_encode( $result, \JSON_PRETTY_PRINT ) );
0 ignored issues
show
Bug introduced by
It seems like wp_json_encode($result, JSON_PRETTY_PRINT) can also be of type false; however, parameter $message of WP_CLI::line() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
			\WP_CLI::line( /** @scrutinizer ignore-type */ \wp_json_encode( $result, \JSON_PRETTY_PRINT ) );
Loading history...
82
		}
83
	}
84
85
	/**
86
	 * CLI transaction refund info.
87
	 *
88
	 * @link https://testcheckout.buckaroo.nl/json/Docs/Api/GET-json-Transaction-Status-transactionKey
89
	 * @param array<string> $args       Arguments.
90
	 * @param array<string> $assoc_args Associative arguments.
91
	 * @return void
92
	 */
93
	public function wp_cli_transaction_refund_info( $args, $assoc_args ) {
94
		$gateway = $this->integration->get_gateway( (int) $assoc_args['config_id'] );
95
96
		foreach ( $args as $transaction_key ) {
97
			$result = $gateway->request( 'GET', 'Transaction/RefundInfo/' . $transaction_key );
98
99
			\WP_CLI::line( \wp_json_encode( $result, \JSON_PRETTY_PRINT ) );
0 ignored issues
show
Bug introduced by
It seems like wp_json_encode($result, JSON_PRETTY_PRINT) can also be of type false; however, parameter $message of WP_CLI::line() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

99
			\WP_CLI::line( /** @scrutinizer ignore-type */ \wp_json_encode( $result, \JSON_PRETTY_PRINT ) );
Loading history...
100
		}
101
	}
102
}
103