Test Failed
Push — issues/2101 ( d7edc6...30f91a )
by Ravinder
05:02
created

Give_DB_Donors::get_donors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 6
Ratio 35.29 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 6
loc 17
rs 9.4285
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
		$this->table_name  = $wpdb->prefix . 'give_customers';
39
		$this->primary_key = 'id';
40
		$this->version     = '1.0';
41
42
		// Set hooks and register table only if instance loading first time.
43
		if ( ! ( Give()->donors instanceof Give_DB_Donors ) ) {
44
			// Setup hook.
45
			add_action( 'profile_update', array( $this, 'update_donor_email_on_user_update' ), 10, 2 );
46
47
			// Install table.
48
			$this->register_table();
49
		}
50
51
	}
52
53
	/**
54
	 * Get columns and formats
55
	 *
56
	 * @since  1.0
57
	 * @access public
58
	 *
59
	 * @return array  Columns and formats.
60
	 */
61 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...
62
		return array(
63
			'id'             => '%d',
64
			'user_id'        => '%d',
65
			'name'           => '%s',
66
			'email'          => '%s',
67
			'payment_ids'    => '%s',
68
			'purchase_value' => '%f',
69
			'purchase_count' => '%d',
70
			'notes'          => '%s',
71
			'date_created'   => '%s',
72
		);
73
	}
74
75
	/**
76
	 * Get default column values
77
	 *
78
	 * @since  1.0
79
	 * @access public
80
	 *
81
	 * @return array  Default column values.
82
	 */
83 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...
84
		return array(
85
			'user_id'        => 0,
86
			'email'          => '',
87
			'name'           => '',
88
			'payment_ids'    => '',
89
			'purchase_value' => 0.00,
90
			'purchase_count' => 0,
91
			'notes'          => '',
92
			'date_created'   => date( 'Y-m-d H:i:s' ),
93
		);
94
	}
95
96
	/**
97
	 * Add a donor
98
	 *
99
	 * @since  1.0
100
	 * @access public
101
	 *
102
	 * @param  array $data
103
	 *
104
	 * @return int|bool
105
	 */
106
	public function add( $data = array() ) {
107
108
		$defaults = array(
109
			'payment_ids' => '',
110
		);
111
112
		$args = wp_parse_args( $data, $defaults );
113
114
		if ( empty( $args['email'] ) ) {
115
			return false;
116
		}
117
118 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...
119
			$args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) );
120
		}
121
122
		$donor = $this->get_donor_by( 'email', $args['email'] );
123
124
		// update an existing donor.
125
		if ( $donor ) {
126
127
			// Update the payment IDs attached to the donor
128
			if ( ! empty( $args['payment_ids'] ) ) {
129
130
				if ( empty( $donor->payment_ids ) ) {
131
132
					$donor->payment_ids = $args['payment_ids'];
133
134
				} else {
135
136
					$existing_ids       = array_map( 'absint', explode( ',', $donor->payment_ids ) );
137
					$payment_ids        = array_map( 'absint', explode( ',', $args['payment_ids'] ) );
138
					$payment_ids        = array_merge( $payment_ids, $existing_ids );
139
					$donor->payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
140
141
				}
142
143
				$args['payment_ids'] = $donor->payment_ids;
144
145
			}
146
147
			$this->update( $donor->id, $args );
148
149
			return $donor->id;
150
151
		} else {
152
153
			return $this->insert( $args, 'donor' );
154
155
		}
156
157
	}
158
159
	/**
160
	 * Delete a donor.
161
	 *
162
	 * NOTE: This should not be called directly as it does not make necessary changes to
163
	 * the payment meta and logs. Use give_donor_delete() instead.
164
	 *
165
	 * @since  1.0
166
	 * @access public
167
	 *
168
	 * @param  bool|string|int $_id_or_email
169
	 *
170
	 * @return bool|int
171
	 */
172
	public function delete( $_id_or_email = false ) {
173
174
		if ( empty( $_id_or_email ) ) {
175
			return false;
176
		}
177
178
		$column = is_email( $_id_or_email ) ? 'email' : 'id';
179
		$donor  = $this->get_donor_by( $column, $_id_or_email );
180
181
		if ( $donor->id > 0 ) {
182
183
			global $wpdb;
184
185
			/**
186
			 * Deleting the donor meta.
187
			 *
188
			 * @since 1.8.14
189
			 */
190
			Give()->donor_meta->delete_all_meta( $donor->id );
191
192
			return $wpdb->delete( $this->table_name, array( 'id' => $donor->id ), array( '%d' ) );
193
194
		} else {
195
			return false;
196
		}
197
198
	}
199
200
	/**
201
	 * Delete a donor by user ID.
202
	 *
203
	 * NOTE: This should not be called directly as it does not make necessary changes to
204
	 * the payment meta and logs. Use give_donor_delete() instead.
205
	 *
206
	 * @since  1.0
207
	 * @access public
208
	 *
209
	 * @param  int|bool $user_id
210
	 *
211
	 * @return bool|int
212
	 */
213
	public function delete_by_user_id( $user_id = false ) {
214
215
		if ( empty( $user_id ) ) {
216
			return false;
217
		}
218
219
		/**
220
		 * Deleting the donor meta.
221
		 *
222
		 * @since 1.8.14
223
		 */
224
		$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 213 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...
225
		if ( ! empty( $donor->id ) ) {
226
			Give()->donor_meta->delete_all_meta( $donor->id );
227
		}
228
229
		global $wpdb;
230
231
		return $wpdb->delete( $this->table_name, array( 'user_id' => $user_id ), array( '%d' ) );
232
	}
233
234
	/**
235
	 * Checks if a donor exists
236
	 *
237
	 * @since  1.0
238
	 * @access public
239
	 *
240
	 * @param  string $value The value to search for. Default is empty.
241
	 * @param  string $field The Donor ID or email to search in. Default is 'email'.
242
	 *
243
	 * @return bool          True is exists, false otherwise.
244
	 */
245
	public function exists( $value = '', $field = 'email' ) {
246
247
		$columns = $this->get_columns();
248
		if ( ! array_key_exists( $field, $columns ) ) {
249
			return false;
250
		}
251
252
		return (bool) $this->get_column_by( 'id', $field, $value );
253
254
	}
255
256
	/**
257
	 * Attaches a payment ID to a donor
258
	 *
259
	 * @since  1.0
260
	 * @access public
261
	 *
262
	 * @param  int $donor_id   Donor ID.
263
	 * @param  int $payment_id Payment ID.
264
	 *
265
	 * @return bool
266
	 */
267
	public function attach_payment( $donor_id = 0, $payment_id = 0 ) {
268
269
		$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...
270
271
		if ( empty( $donor->id ) ) {
272
			return false;
273
		}
274
275
		// Attach the payment, but don't increment stats, as this function previously did not
276
		return $donor->attach_payment( $payment_id, false );
277
278
	}
279
280
	/**
281
	 * Removes a payment ID from a donor.
282
	 *
283
	 * @since  1.0
284
	 * @access public
285
	 *
286
	 * @param  int $donor_id   Donor ID.
287
	 * @param  int $payment_id Payment ID.
288
	 *
289
	 * @return bool
290
	 */
291
	public function remove_payment( $donor_id = 0, $payment_id = 0 ) {
292
293
		$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...
294
295
		if ( ! $donor ) {
296
			return false;
297
		}
298
299
		// Remove the payment, but don't decrease stats, as this function previously did not
300
		return $donor->remove_payment( $payment_id, false );
301
302
	}
303
304
	/**
305
	 * Increments donor's donation stats.
306
	 *
307
	 * @access public
308
	 *
309
	 * @param int   $donor_id Donor ID.
310
	 * @param float $amount   THe amount to increase.
311
	 *
312
	 * @return bool
313
	 */
314 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...
315
316
		$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...
317
318
		if ( empty( $donor->id ) ) {
319
			return false;
320
		}
321
322
		$increased_count = $donor->increase_purchase_count();
323
		$increased_value = $donor->increase_value( $amount );
324
325
		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...
326
327
	}
328
329
	/**
330
	 * Decrements donor's donation stats.
331
	 *
332
	 * @since  1.0
333
	 * @access public
334
	 *
335
	 * @param  int   $donor_id Donor ID.
336
	 * @param  float $amount   Amount.
337
	 *
338
	 * @return bool
339
	 */
340 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...
341
342
		$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...
343
344
		if ( ! $donor ) {
345
			return false;
346
		}
347
348
		$decreased_count = $donor->decrease_donation_count();
349
		$decreased_value = $donor->decrease_value( $amount );
350
351
		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...
352
353
	}
354
355
	/**
356
	 * Updates the email address of a donor record when the email on a user is updated
357
	 *
358
	 * @since  1.4.3
359
	 * @access public
360
	 *
361
	 * @param  int          $user_id       User ID.
362
	 * @param  WP_User|bool $old_user_data User data.
363
	 *
364
	 * @return bool
365
	 */
366
	public function update_donor_email_on_user_update( $user_id = 0, $old_user_data = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_user_data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
367
368
		$donor = new Give_Donor( $user_id, true );
0 ignored issues
show
Documentation introduced by
$user_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...
369
370
		if ( ! $donor ) {
371
			return false;
372
		}
373
374
		$user = get_userdata( $user_id );
375
376
		if ( ! empty( $user ) && $user->user_email !== $donor->email ) {
377
378
			if ( ! $this->get_donor_by( 'email', $user->user_email ) ) {
379
380
				$success = $this->update( $donor->id, array( 'email' => $user->user_email ) );
381
382
				if ( $success ) {
383
					// Update some payment meta if we need to
384
					$payments_array = explode( ',', $donor->payment_ids );
385
386
					if ( ! empty( $payments_array ) ) {
387
388
						foreach ( $payments_array as $payment_id ) {
389
390
							give_update_payment_meta( $payment_id, 'email', $user->user_email );
391
392
						}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
393
394
					}
395
396
					/**
397
					 * Fires after updating donor email on user update.
398
					 *
399
					 * @since 1.4.3
400
					 *
401
					 * @param  WP_User    $user  WordPress User object.
402
					 * @param  Give_Donor $donor Give donor object.
403
					 */
404
					do_action( 'give_update_donor_email_on_user_update', $user, $donor );
405
406
				}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
407
408
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
409
410
		}
411
412
	}
413
414
	/**
415
	 * Retrieves a single donor from the database
416
	 *
417
	 * @since  1.0
418
	 * @access public
419
	 *
420
	 * @param  string $field ID or email. Default is 'id'.
421
	 * @param  mixed  $value The Customer ID or email to search. Default is 0.
422
	 *
423
	 * @return mixed         Upon success, an object of the donor. Upon failure, NULL
424
	 */
425
	public function get_donor_by( $field = 'id', $value = 0 ) {
426
		$value = sanitize_text_field( $value );
427
428
		// Bailout.
429
		if ( empty( $field ) || empty( $value ) ) {
430
			return null;
431
		}
432
433
		// Verify values.
434
		if ( 'id' === $field || 'user_id' === $field ) {
435
			// Make sure the value is numeric to avoid casting objects, for example,
436
			// to int 1.
437
			if ( ! is_numeric( $value ) ) {
438
				return false;
439
			}
440
441
			$value = absint( $value );
442
443
			if ( $value < 1 ) {
444
				return false;
445
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
446
447
		} elseif ( 'email' === $field ) {
448
449
			if ( ! is_email( $value ) ) {
450
				return false;
451
			}
452
453
			$value = trim( $value );
454
		}
455
456
		// Bailout
457
		if ( ! $value ) {
458
			return false;
459
		}
460
461
		// Set query params.
462
		switch ( $field ) {
463
			case 'id':
464
				$args['donor'] = $value;
465
				break;
466
			case 'email':
467
				$args['email'] = $value;
468
				break;
469
			case 'user_id':
470
				$args['user'] = $value;
471
				break;
472
			default:
473
				return false;
474
		}
475
476
		// Get donors.
477
		$donor = new Give_Donors_Query( $args );
478
479
		if ( ! $donor = $donor->get_donors() ) {
480
			// Look for donor from an additional email.
481
			$args = array(
482
				'meta_query' => array(
0 ignored issues
show
introduced by
Detected usage of meta_query, possible slow query.
Loading history...
483
					array(
484
						'key'   => 'additional_email',
485
						'value' => $value,
486
					),
487
				),
488
			);
489
490
			$donor = new Give_Donors_Query( $args );
491
			$donor = $donor->get_donors();
492
493
			if ( ! empty( $donor ) ) {
494
				return $donor;
495
			}
496
497
			return false;
498
		}
499
500
		return $donor;
501
	}
502
503
	/**
504
	 * Retrieve donors from the database.
505
	 *
506
	 * @since  1.0
507
	 * @access public
508
	 *
509
	 * @param  array $args
510
	 *
511
	 * @return array|object|null Donors array or object. Null if not found.
512
	 */
513
	public function get_donors( $args = array() ) {
514
		$this->bc_v1814_params( $args );
515
516
		$cache_key = md5( 'give_donors_' . serialize( $args ) );
517
518
		$donors = wp_cache_get( $cache_key, 'donors' );
519
520 View Code Duplication
		if ( $donors === false ) {
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...
introduced by
Found "=== false". Use Yoda Condition checks, you must
Loading history...
521
			$donors = new Give_Donors_Query( $args );
522
			$donors = $donors->get_donors();
523
524
			wp_cache_set( $cache_key, $donors, 'donors', 3600 );
525
		}
526
527
		return $donors;
528
529
	}
530
531
532
	/**
533
	 * Count the total number of donors in the database
534
	 *
535
	 * @since  1.0
536
	 * @access public
537
	 *
538
	 * @param  array $args
539
	 *
540
	 * @return int         Total number of donors.
541
	 */
542
	public function count( $args = array() ) {
543
		$this->bc_v1814_params( $args );
544
		$args['count'] = true;
545
546
		$cache_key = md5( 'give_donors_count' . serialize( $args ) );
547
		$count     = wp_cache_get( $cache_key, 'donors' );
548
549 View Code Duplication
		if ( $count === false ) {
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...
introduced by
Found "=== false". Use Yoda Condition checks, you must
Loading history...
550
			$donors = new Give_Donors_Query( $args );
551
			$count  = $donors->get_donors();
552
553
			wp_cache_set( $cache_key, $count, 'donors', 3600 );
554
		}
555
556
		return absint( $count );
557
558
	}
559
560
	/**
561
	 * Create the table
562
	 *
563
	 * @since  1.0
564
	 * @access public
565
	 *
566
	 * @return void
567
	 */
568 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...
569
570
		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
571
572
		$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...
573
		id bigint(20) NOT NULL AUTO_INCREMENT,
574
		user_id bigint(20) NOT NULL,
575
		email varchar(50) NOT NULL,
576
		name mediumtext NOT NULL,
577
		purchase_value mediumtext NOT NULL,
578
		purchase_count bigint(20) NOT NULL,
579
		payment_ids longtext NOT NULL,
580
		notes longtext NOT NULL,
581
		date_created datetime NOT NULL,
582
		PRIMARY KEY  (id),
583
		UNIQUE KEY email (email),
584
		KEY user (user_id)
585
		) CHARACTER SET utf8 COLLATE utf8_general_ci;";
586
587
		dbDelta( $sql );
588
589
		update_option( $this->table_name . '_db_version', $this->version );
590
	}
591
592
	/**
593
	 * Check if the Customers table was ever installed
594
	 *
595
	 * @since  1.4.3
596
	 * @access public
597
	 *
598
	 * @return bool Returns if the donors table was installed and upgrade routine run.
599
	 */
600
	public function installed() {
601
		return $this->table_exists( $this->table_name );
602
	}
603
604
	/**
605
	 * Add backward compatibility for deprecated param
606
	 *
607
	 * @since  1.8.14
608
	 * @access private
609
	 *
610
	 * @param $args
611
	 */
612
	private function bc_v1814_params( &$args ) {
613
		// Backward compatibility: user_id
614
		if ( ! empty( $args['user_id'] ) ) {
615
			$args['user'] = $args['user_id'];
616
		}
617
618
		// Backward compatibility: id
619
		if ( ! empty( $args['id'] ) ) {
620
			$args['donor'] = $args['id'];
621
		}
622
623
		// Backward compatibility: name
624
		if ( ! empty( $args['name'] ) ) {
625
			$args['s'] = "name:{$args['name']}";
626
		}
627
628
		// Backward compatibility: date
629
		// Donors created for a specific date or in a date range.
630
		if ( ! empty( $args['date'] ) ) {
631
632
			if ( is_array( $args['date'] ) ) {
633
634 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...
635
					$args['date_query']['after'] = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
636
				}
637
638 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...
639
					$args['date_query']['before'] = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
640
				}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
641
642
			} else {
643
644
				$args['date_query']['year']  = date( 'Y', strtotime( $args['date'] ) );
645
				$args['date_query']['month'] = date( 'm', strtotime( $args['date'] ) );
646
				$args['date_query']['day']   = date( 'd', strtotime( $args['date'] ) );
647
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
648
649
		}
650
	}
651
}
652