Test Failed
Push — develop ( b72058...5cbfdc )
by Reüel
04:45
created

CustomerQuery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_customers() 0 24 2
A __construct() 0 6 1
1
<?php
2
/**
3
 * Mollie customer query.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
12
13
/**
14
 * Title: Mollie customer query
15
 * Description:
16
 * Copyright: 2005-2020 Pronamic
17
 * Company: Pronamic
18
 *
19
 * @author  Remco Tolsma
20
 * @version 3.0.0
21
 * @since   3.0.0
22
 */
23
class CustomerQuery {
24
	/**
25
	 * Construct customer query.
26
	 *
27
	 * @param array $args Query arguments.
28
	 */
29
	public function __construct( $args = array() ) {
30
		$this->args = \wp_parse_args(
0 ignored issues
show
Bug Best Practice introduced by
The property args does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
			$args,
32
			array(
33
				'user_id'         => null,
34
				'organization_id' => null,
35
			)
36
		);
37
	}
38
39
	/**
40
	 * Get customers.
41
	 *
42
	 * @return array
43
	 */
44
	public function get_customers() {
45
		global $wpdb;
46
47
		$where = '1 = 1';
48
49
		if ( array_key_exists( 'user_id', $this->args ) ) {
50
			$where .= $wpdb->prepare( ' AND mollie_customer_user.user_id = %d', $this->args['user_id'] );
51
		}
52
53
		$query = "
54
			SELECT
55
				mollie_customer.mollie_id,
56
				mollie_customer.test_mode
57
			FROM
58
				$wpdb->pronamic_pay_mollie_customer_users AS mollie_customer_user
59
					INNER JOIN
60
				$wpdb->pronamic_pay_mollie_customers AS mollie_customer
61
						ON mollie_customer_user.customer_id = mollie_customer.id
62
			WHERE
63
				 $where
64
			;
65
		";
66
67
		return $wpdb->get_results( $query );
68
	}
69
}
70