Give_DB_Donor_Meta::get_columns()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Donor Meta DB class
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/DB Donor Meta
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.6
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Class Give_DB_Donor_Meta
19
 *
20
 * This class is for interacting with the donor meta database table.
21
 *
22
 * @since 1.6
23
 */
24
class Give_DB_Donor_Meta extends Give_DB_Meta {
25
	
26
	/**
27
	 * Meta supports.
28
	 *
29
	 * @since  2.0
30
	 * @access protected
31
	 * @var array
32
	 */
33
	protected $supports = array();
34
35
	/**
36
	 * Meta type
37
	 *
38
	 * @since  2.0
39
	 * @access public
40
	 *
41
	 * @var string
42
	 */
43
	public $meta_type = 'donor';
44
45
46
	/**
47
	 * Give_DB_Donor_Meta constructor.
48
	 *
49
	 * @access  public
50
	 * @since   1.6
51
	 */
52 View Code Duplication
	public function __construct() {
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...
53
		/* @var WPDB $wpdb */
54
		global $wpdb;
55
56
		$wpdb->donormeta   = $this->table_name = $wpdb->prefix . 'give_donormeta';
57
		$this->primary_key = 'meta_id';
58
		$this->version     = '1.0';
59
60
		parent::__construct();
61
62
		$this->bc_200_params();
63
		$this->register_table();
64
	}
65
66
	/**
67
	 * Get table columns and data types.
68
	 *
69
	 * @access  public
70
	 * @since   1.6
71
	 *
72
	 * @return  array  Columns and formats.
73
	 */
74
	public function get_columns() {
75
		return array(
76
			'meta_id'     => '%d',
77
			'donor_id' => '%d',
78
			'meta_key'    => '%s',
0 ignored issues
show
introduced by
Detected usage of meta_key, possible slow query.
Loading history...
79
			'meta_value'  => '%s',
0 ignored issues
show
introduced by
Detected usage of meta_value, possible slow query.
Loading history...
80
		);
81
	}
82
83
	/**
84
	 * Add backward compatibility for old table name
85
	 *
86
	 * @since  2.0
87
	 * @access private
88
	 * @global wpdb $wpdb
89
	 */
90
	private function bc_200_params() {
91
		/* @var wpdb $wpdb */
92
		global $wpdb;
93
94 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...
95
			! give_has_upgrade_completed( 'v20_rename_donor_tables' ) &&
96
			$wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s","{$wpdb->prefix}give_customermeta" ) )
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...
97
		) {
98
			$wpdb->donormeta = $this->table_name = "{$wpdb->prefix}give_customermeta";
99
			$this->meta_type = 'customer';
100
		}
101
102
		$wpdb->customermeta = $wpdb->donormeta;
103
	}
104
105
	/**
106
	 * Check if current id is valid
107
	 *
108
	 * @since  2.0
109
	 * @access protected
110
	 *
111
	 * @param $ID
112
	 *
113
	 * @return bool
114
	 */
115
	protected function is_valid_post_type( $ID ) {
116
		return $ID && true;
117
	}
118
119
}
120