Test Failed
Push — develop ( 13fc2a...744f0f )
by Reüel
04:50
created

CustomerQuery::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
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
				'profile_id'      => null,
36
			)
37
		);
38
	}
39
40
	/**
41
	 * Get customers.
42
	 *
43
	 * @return array
44
	 */
45
	public function get_customers() {
46
		global $wpdb;
47
48
		$where = '1 = 1';
49
50
		if ( array_key_exists( 'user_id', $this->args ) ) {
51
			$where .= $wpdb->prepare( ' AND mollie_customer_user.user_id = %d', $this->args['user_id'] );
52
		}
53
54
		$query = "
55
			SELECT
56
				mollie_customer.mollie_id,
57
				mollie_customer.test_mode
58
			FROM
59
				$wpdb->pronamic_pay_mollie_customer_users AS mollie_customer_user
60
					INNER JOIN
61
				$wpdb->pronamic_pay_mollie_customers AS mollie_customer
62
						ON mollie_customer_user.customer_id = mollie_customer.id
63
			WHERE
64
				 $where
65
			;
66
		";
67
68
		return $wpdb->get_results( $query );
69
	}
70
}
71