Test Failed
Push — issues/2531 ( 9ee8d9...57cdd6 )
by Ravinder
04:36
created

Give_DB_Donors::create_table()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 5

Duplication

Lines 23
Ratio 88.46 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 23
loc 26
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Donors DB
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_DB_Donors
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Give_DB_Donors Class
19
 *
20
 * This class is for interacting with the donor database table.
21
 *
22
 * @since 1.0
23
 */
24
class Give_DB_Donors extends Give_DB {
25
26
	/**
27
	 * Give_DB_Donors constructor.
28
	 *
29
	 * Set up the Give DB Donor class.
30
	 *
31
	 * @since  1.0
32
	 * @access public
33
	 */
34
	public function __construct() {
35
		/* @var WPDB $wpdb */
36
		global $wpdb;
37
38
		$wpdb->donors      = $this->table_name = "{$wpdb->prefix}give_donors";
39
		$this->primary_key = 'id';
40
		$this->version     = '1.0';
41
42
		$this->bc_200_params();
43
44
		// Set hooks and register table only if instance loading first time.
45
		if ( ! ( Give()->donors instanceof Give_DB_Donors ) ) {
46
			// Install table.
47
			$this->register_table();
48
		}
49
50
	}
51
52
	/**
53
	 * Get columns and formats
54
	 *
55
	 * @since  1.0
56
	 * @access public
57
	 *
58
	 * @return array  Columns and formats.
59
	 */
60 View Code Duplication
	public function get_columns() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
		return array(
62
			'id'              => '%d',
63
			'user_id'         => '%d',
64
			'name'            => '%s',
65
			'email'           => '%s',
66
			'payment_ids'     => '%s',
67
			'purchase_value'  => '%f',
68
			'purchase_count'  => '%d',
69
			'notes'           => '%s',
70
			'date_created'    => '%s',
71
			'token'           => '%s',
72
			'verify_key'      => '%s',
73
			'verify_throttle' => '%s',
74
		);
75
	}
76
77
	/**
78
	 * Get default column values
79
	 *
80
	 * @since  1.0
81
	 * @access public
82
	 *
83
	 * @return array  Default column values.
84
	 */
85 View Code Duplication
	public function get_column_defaults() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
		return array(
87
			'user_id'         => 0,
88
			'email'           => '',
89
			'name'            => '',
90
			'payment_ids'     => '',
91
			'purchase_value'  => 0.00,
92
			'purchase_count'  => 0,
93
			'notes'           => '',
94
			'date_created'    => date( 'Y-m-d H:i:s' ),
95
			'token'           => '',
96
			'verify_key'      => '',
97
			'verify_throttle' => '',
98
		);
99
	}
100
101
	/**
102
	 * Add a donor
103
	 *
104
	 * @param  array $data List of donor data to add.
105
	 *
106
	 * @since  1.0
107
	 * @access public
108
	 *
109
	 * @return int|bool
110
	 */
111
	public function add( $data = array() ) {
112
113
		$defaults = array(
114
			'payment_ids' => '',
115
		);
116
117
		$args = wp_parse_args( $data, $defaults );
118
119
		if ( empty( $args['email'] ) ) {
120
			return false;
121
		}
122
123 View Code Duplication
		if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
			$args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) );
125
		}
126
127
		$donor = $this->get_donor_by( 'email', $args['email'] );
128
129
		// update an existing donor.
130
		if ( $donor ) {
131
132
			// Update the payment IDs attached to the donor
133
			if ( ! empty( $args['payment_ids'] ) ) {
134
135
				if ( empty( $donor->payment_ids ) ) {
136
137
					$donor->payment_ids = $args['payment_ids'];
138
139
				} else {
140
141
					$existing_ids       = array_map( 'absint', explode( ',', $donor->payment_ids ) );
142
					$payment_ids        = array_map( 'absint', explode( ',', $args['payment_ids'] ) );
143
					$payment_ids        = array_merge( $payment_ids, $existing_ids );
144
					$donor->payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
145
146
				}
147
148
				$args['payment_ids'] = $donor->payment_ids;
149
150
			}
151
152
			$this->update( $donor->id, $args );
153
154
			return $donor->id;
155
156
		} else {
157
158
			return $this->insert( $args, 'donor' );
159
160
		}
161
162
	}
163
164
165
	/**
166
	 * Update a donor.
167
	 *
168
	 *
169
	 * @param int    $row_id
170
	 * @param array  $data
171
	 * @param string $where
172
	 *
173
	 * @return bool
174
	 */
175
	public function update( $row_id, $data = array(), $where = '' ) {
176
177
		$status = parent::update( $row_id, $data, $where );
178
179
		if ( $status ) {
180
			Give_Cache::delete_group( $row_id, 'give-donors' );
181
		}
182
183
		return $status;
184
	}
185
186
	/**
187
	 * Insert a donor.
188
	 *
189
	 * @param array  $data
190
	 * @param string $type
191
	 *
192
	 * @return int
193
	 */
194
	public function insert( $data, $type = '' ) {
195
		$donor_id = parent::insert( $data, $type );
196
197
		if ( $donor_id ) {
198
			Give_Cache::delete_group( $donor_id, 'give-donors' );
199
		}
200
201
		return $donor_id;
202
	}
203
204
	/**
205
	 * Delete a donor.
206
	 *
207
	 * NOTE: This should not be called directly as it does not make necessary changes to
208
	 * the payment meta and logs. Use give_donor_delete() instead.
209
	 *
210
	 * @param  bool|string|int $_id_or_email ID or Email of Donor.
211
	 *
212
	 * @since  1.0
213
	 * @access public
214
	 *
215
	 * @return bool|int
216
	 */
217
	public function delete( $_id_or_email = false ) {
218
219
		if ( empty( $_id_or_email ) ) {
220
			return false;
221
		}
222
223
		$column = is_email( $_id_or_email ) ? 'email' : 'id';
224
		$donor  = $this->get_donor_by( $column, $_id_or_email );
225
226
		if ( $donor->id > 0 ) {
227
228
			global $wpdb;
229
230
			/**
231
			 * Deleting the donor meta.
232
			 *
233
			 * @since 1.8.14
234
			 */
235
			Give()->donor_meta->delete_all_meta( $donor->id );
236
237
			// Cache already deleted in delete_all_meta fn.
238
239
			return $wpdb->delete( $this->table_name, array( 'id' => $donor->id ), array( '%d' ) );
240
241
		} else {
242
			return false;
243
		}
244
245
	}
246
247
	/**
248
	 * Delete a donor by user ID.
249
	 *
250
	 * NOTE: This should not be called directly as it does not make necessary changes to
251
	 * the payment meta and logs. Use give_donor_delete() instead.
252
	 *
253
	 * @since  1.0
254
	 * @access public
255
	 *
256
	 * @param  int|bool $user_id
257
	 *
258
	 * @return bool|int
259
	 */
260
	public function delete_by_user_id( $user_id = false ) {
261
		global $wpdb;
262
263
		if ( empty( $user_id ) ) {
264
			return false;
265
		}
266
267
		/**
268
		 * Deleting the donor meta.
269
		 *
270
		 * @since 1.8.14
271
		 */
272
		$donor = new Give_Donor( $user_id, true );
0 ignored issues
show
Bug introduced by
It seems like $user_id defined by parameter $user_id on line 260 can also be of type integer; however, Give_Donor::__construct() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
273
		if ( ! empty( $donor->id ) ) {
274
			Give()->donor_meta->delete_all_meta( $donor->id );
275
		}
276
277
		// Cache is already deleted in delete_all_meta fn.
278
279
		return $wpdb->delete( $this->table_name, array( 'user_id' => $user_id ), array( '%d' ) );
280
	}
281
282
	/**
283
	 * Checks if a donor exists
284
	 *
285
	 * @param  string $value The value to search for. Default is empty.
286
	 * @param  string $field The Donor ID or email to search in. Default is 'email'.
287
	 *
288
	 * @since  1.0
289
	 * @access public
290
	 *
291
	 * @return bool          True is exists, false otherwise.
292
	 */
293
	public function exists( $value = '', $field = 'email' ) {
294
295
		$columns = $this->get_columns();
296
		if ( ! array_key_exists( $field, $columns ) ) {
297
			return false;
298
		}
299
300
		return (bool) $this->get_column_by( 'id', $field, $value );
301
302
	}
303
304
	/**
305
	 * Attaches a payment ID to a donor
306
	 *
307
	 * @since  1.0
308
	 * @access public
309
	 *
310
	 * @param  int $donor_id   Donor ID.
311
	 * @param  int $payment_id Payment ID.
312
	 *
313
	 * @return bool
314
	 */
315
	public function attach_payment( $donor_id = 0, $payment_id = 0 ) {
316
317
		$donor = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
318
319
		if ( empty( $donor->id ) ) {
320
			return false;
321
		}
322
323
		// Attach the payment, but don't increment stats, as this function previously did not
324
		return $donor->attach_payment( $payment_id, false );
325
326
	}
327
328
	/**
329
	 * Removes a payment ID from a donor.
330
	 *
331
	 * @since  1.0
332
	 * @access public
333
	 *
334
	 * @param  int $donor_id   Donor ID.
335
	 * @param  int $payment_id Payment ID.
336
	 *
337
	 * @return bool
338
	 */
339
	public function remove_payment( $donor_id = 0, $payment_id = 0 ) {
340
341
		$donor = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
342
343
		if ( ! $donor ) {
344
			return false;
345
		}
346
347
		// Remove the payment, but don't decrease stats, as this function previously did not
348
		return $donor->remove_payment( $payment_id, false );
349
350
	}
351
352
	/**
353
	 * Increments donor's donation stats.
354
	 *
355
	 * @access public
356
	 *
357
	 * @param int   $donor_id Donor ID.
358
	 * @param float $amount   THe amount to increase.
359
	 *
360
	 * @return bool
361
	 */
362 View Code Duplication
	public function increment_stats( $donor_id = 0, $amount = 0.00 ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
363
364
		$donor = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
365
366
		if ( empty( $donor->id ) ) {
367
			return false;
368
		}
369
370
		$increased_count = $donor->increase_purchase_count();
371
		$increased_value = $donor->increase_value( $amount );
372
373
		return ( $increased_count && $increased_value ) ? true : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression $increased_count of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
374
375
	}
376
377
	/**
378
	 * Decrements donor's donation stats.
379
	 *
380
	 * @since  1.0
381
	 * @access public
382
	 *
383
	 * @param  int   $donor_id Donor ID.
384
	 * @param  float $amount   Amount.
385
	 *
386
	 * @return bool
387
	 */
388 View Code Duplication
	public function decrement_stats( $donor_id = 0, $amount = 0.00 ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
389
390
		$donor = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
391
392
		if ( ! $donor ) {
393
			return false;
394
		}
395
396
		$decreased_count = $donor->decrease_donation_count();
397
		$decreased_value = $donor->decrease_value( $amount );
398
399
		return ( $decreased_count && $decreased_value ) ? true : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression $decreased_count of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
400
401
	}
402
403
	/**
404
	 * Retrieves a single donor from the database
405
	 *
406
	 * @since  1.0
407
	 * @access public
408
	 *
409
	 * @param  string $field ID or email. Default is 'id'.
410
	 * @param  mixed  $value The Customer ID or email to search. Default is 0.
411
	 *
412
	 * @return mixed         Upon success, an object of the donor. Upon failure, NULL
413
	 */
414
	public function get_donor_by( $field = 'id', $value = 0 ) {
415
		$value = sanitize_text_field( $value );
416
417
		// Bailout.
418
		if ( empty( $field ) || empty( $value ) ) {
419
			return null;
420
		}
421
422
		// Verify values.
423
		if ( 'id' === $field || 'user_id' === $field ) {
424
			// Make sure the value is numeric to avoid casting objects, for example,
425
			// to int 1.
426
			if ( ! is_numeric( $value ) ) {
427
				return false;
428
			}
429
430
			$value = absint( $value );
431
432
			if ( $value < 1 ) {
433
				return false;
434
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
435
436
		} elseif ( 'email' === $field ) {
437
438
			if ( ! is_email( $value ) ) {
439
				return false;
440
			}
441
442
			$value = trim( $value );
443
		}
444
445
		// Bailout
446
		if ( ! $value ) {
447
			return false;
448
		}
449
450
		// Set query params.
451
		switch ( $field ) {
452
			case 'id':
453
				$args['donor'] = $value;
454
				break;
455
			case 'email':
456
				$args['email'] = $value;
457
				break;
458
			case 'user_id':
459
				$args['user'] = $value;
460
				break;
461
			default:
462
				return false;
463
		}
464
465
		// Get donors.
466
		$donor = new Give_Donors_Query( $args );
467
468
		if ( ! $donor = $donor->get_donors() ) {
469
			// Look for donor from an additional email.
470
			$args = array(
471
				'meta_query' => array(
0 ignored issues
show
introduced by
Detected usage of meta_query, possible slow query.
Loading history...
472
					array(
473
						'key'   => 'additional_email',
474
						'value' => $value,
475
					),
476
				),
477
			);
478
479
			$donor = new Give_Donors_Query( $args );
480
			$donor = $donor->get_donors();
481
482
			if ( empty( $donor ) ) {
483
				return false;
484
			}
485
		}
486
487
		return current( $donor );
488
	}
489
490
	/**
491
	 * Retrieve donors from the database.
492
	 *
493
	 * @since  1.0
494
	 * @access public
495
	 *
496
	 * @param  array $args
497
	 *
498
	 * @return array|object|null Donors array or object. Null if not found.
499
	 */
500
	public function get_donors( $args = array() ) {
501
		$this->bc_1814_params( $args );
502
503
		$donors = new Give_Donors_Query( $args );
504
505
		return $donors->get_donors();
506
507
	}
508
509
510
	/**
511
	 * Count the total number of donors in the database
512
	 *
513
	 * @since  1.0
514
	 * @access public
515
	 *
516
	 * @param  array $args
517
	 *
518
	 * @return int         Total number of donors.
519
	 */
520
	public function count( $args = array() ) {
521
		$this->bc_1814_params( $args );
522
		$args['count'] = true;
523
524
		$cache_key = md5( 'give_donors_count' . serialize( $args ) );
525
		$count     = Give_Cache::get_group( $cache_key, 'donors' );
526
527
		if ( is_null( $count ) ) {
528
			$donors = new Give_Donors_Query( $args );
529
			$count  = $donors->get_donors();
530
531
			Give_Cache::set_group( $cache_key, $count, 'donors', 3600 );
532
		}
533
534
		return absint( $count );
535
536
	}
537
538
	/**
539
	 * Create the table
540
	 *
541
	 * @since  1.0
542
	 * @access public
543
	 *
544
	 * @return void
545
	 */
546 View Code Duplication
	public function create_table() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
547
548
		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
549
550
		$sql = "CREATE TABLE " . $this->table_name . " (
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal CREATE TABLE does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal (\n id bigint(20...OLLATE utf8_general_ci; does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
551
		id bigint(20) NOT NULL AUTO_INCREMENT,
552
		user_id bigint(20) NOT NULL,
553
		email varchar(50) NOT NULL,
554
		name mediumtext NOT NULL,
555
		purchase_value mediumtext NOT NULL,
556
		purchase_count bigint(20) NOT NULL,
557
		payment_ids longtext NOT NULL,
558
		notes longtext NOT NULL,
559
		date_created datetime NOT NULL,
560
		token VARCHAR(255) CHARACTER SET utf8 NOT NULL,
561
		verify_key VARCHAR(255) CHARACTER SET utf8 NOT NULL,
562
		verify_throttle DATETIME NOT NULL,
563
		PRIMARY KEY  (id),
564
		UNIQUE KEY email (email),
565
		KEY user (user_id)
566
		) CHARACTER SET utf8 COLLATE utf8_general_ci;";
567
568
		dbDelta( $sql );
569
570
		update_option( $this->table_name . '_db_version', $this->version );
571
	}
572
573
	/**
574
	 * Add backward compatibility for old table name
575
	 *
576
	 * @since  2.0
577
	 * @access private
578
	 * @global wpdb $wpdb
579
	 */
580
	private function bc_200_params() {
581
		/* @var wpdb $wpdb */
582
		global $wpdb;
583
584 View Code Duplication
		if (
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
585
			! give_has_upgrade_completed( 'v20_rename_donor_tables' ) &&
586
			$wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_customers" ) )
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
Coding Style Comprehensibility introduced by
The string literal SHOW TABLES LIKE %s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
587
		) {
588
			$wpdb->donors = $this->table_name = "{$wpdb->prefix}give_customers";
589
		}
590
	}
591
592
	/**
593
	 * Add backward compatibility for deprecated param
594
	 *
595
	 * @since  1.8.14
596
	 * @access private
597
	 *
598
	 * @param $args
599
	 */
600
	private function bc_1814_params( &$args ) {
601
		// Backward compatibility: user_id
602
		if ( ! empty( $args['user_id'] ) ) {
603
			$args['user'] = $args['user_id'];
604
		}
605
606
		// Backward compatibility: id
607
		if ( ! empty( $args['id'] ) ) {
608
			$args['donor'] = $args['id'];
609
		}
610
611
		// Backward compatibility: name
612
		if ( ! empty( $args['name'] ) ) {
613
			$args['s'] = "name:{$args['name']}";
614
		}
615
616
		// Backward compatibility: date
617
		// Donors created for a specific date or in a date range.
618
		if ( ! empty( $args['date'] ) ) {
619
620
			if ( is_array( $args['date'] ) ) {
621
622 View Code Duplication
				if ( ! empty( $args['date']['start'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
623
					$args['date_query']['after'] = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
624
				}
625
626 View Code Duplication
				if ( ! empty( $args['date']['end'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
627
					$args['date_query']['before'] = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
628
				}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
629
630
			} else {
631
632
				$args['date_query']['year']  = date( 'Y', strtotime( $args['date'] ) );
633
				$args['date_query']['month'] = date( 'm', strtotime( $args['date'] ) );
634
				$args['date_query']['day']   = date( 'd', strtotime( $args['date'] ) );
635
			}
636
		}
637
	}
638
}
639