Failed Conditions
Push — master ( b549f2...090668 )
by Remco
10:21 queued 03:46
created

CustomerQuery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 55
ccs 14
cts 14
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_customers() 0 27 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 2.1.0
21
 * @since   2.1.0
22
 */
23
class CustomerQuery {
24
	/**
25
	 * Query arguments.
26
	 *
27
	 * @var array<string, int>
28
	 */
29
	private $args;
30
31
	/**
32
	 * Construct customer query.
33
	 *
34
	 * @param array<string, int> $args Query arguments.
35
	 */
36 24
	public function __construct( $args = array() ) {
37 24
		$this->args = \wp_parse_args(
38 24
			$args,
39
			array(
40 24
				'user_id'         => null,
41
				'organization_id' => null,
42
			)
43
		);
44 24
	}
45
46
	/**
47
	 * Get customers.
48
	 *
49
	 * @return array<object>
50
	 */
51 24
	public function get_customers() {
52 24
		global $wpdb;
53
54 24
		$where = '1 = 1';
55
56 24
		if ( array_key_exists( 'user_id', $this->args ) ) {
57 24
			$where .= $wpdb->prepare( ' AND mollie_customer_user.user_id = %d', $this->args['user_id'] );
58
		}
59
60
		$query = "
61
			SELECT
62
				mollie_customer.mollie_id,
63
				mollie_customer.test_mode,
64
				mollie_customer.name,
65
				mollie_customer.email
66
			FROM
67 24
				$wpdb->pronamic_pay_mollie_customer_users AS mollie_customer_user
68
					INNER JOIN
69 24
				$wpdb->pronamic_pay_mollie_customers AS mollie_customer
70
						ON mollie_customer_user.customer_id = mollie_customer.id
71
			WHERE
72 24
				 $where
73
			;
74
		";
75
76
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Query is prepared.
77 24
		return $wpdb->get_results( $query );
78
	}
79
}
80