Give_DB_Payment_Meta::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Payment Meta DB class
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/DB Payment Meta
7
 * @copyright   Copyright (c) 2016, GiveWP
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       2.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Class Give_DB_Payment_Meta
19
 *
20
 * This class is for interacting with the payment meta database table.
21
 *
22
 * @since 2.0
23
 */
24
class Give_DB_Payment_Meta extends Give_DB_Meta {
25
	/**
26
	 * Post type
27
	 *
28
	 * @since  2.0
29
	 * @access protected
30
	 * @var bool
31
	 */
32
	protected $post_type = 'give_payment';
33
34
	/**
35
	 * Meta type
36
	 *
37
	 * @since  2.0
38
	 * @access protected
39
	 * @var bool
40
	 */
41
	protected $meta_type = 'donation';
42
43
	/**
44
	 * Give_DB_Payment_Meta constructor.
45
	 *
46
	 * @access  public
47
	 * @since   2.0
48
	 */
49
	public function __construct() {
50
		/* @var WPDB $wpdb */
51
		global $wpdb;
52
53
		// @todo: We leave $wpdb->paymentmeta for backward compatibility, use $wpdb->donationmeta instead. We can remove it after 2.1.3.
54
		$wpdb->paymentmeta = $wpdb->donationmeta = $this->table_name = $wpdb->prefix . 'give_donationmeta';
55
		$this->version     = '1.0';
56
57
		// Backward compatibility.
58
		if ( ! give_has_upgrade_completed( 'v220_rename_donation_meta_type' ) ) {
59
			$this->meta_type = 'payment';
0 ignored issues
show
Documentation Bug introduced by
The property $meta_type was declared of type boolean, but 'payment' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
60
			$wpdb->paymentmeta = $wpdb->donationmeta = $this->table_name = $wpdb->prefix . 'give_paymentmeta';
61
		}
62
63
		parent::__construct();
64
	}
65
66
	/**
67
	 * Get table columns and data types.
68
	 *
69
	 * @access  public
70
	 * @since   2.0
71
	 *
72
	 * @return  array  Columns and formats.
73
	 */
74
	public function get_columns() {
75
		return array(
76
			'meta_id'               => '%d',
77
			"{$this->meta_type}_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
	 * check if custom meta table enabled or not.
85
	 *
86
	 * @since  2.0
87
	 * @access protected
88
	 * @return bool
89
	 */
90
	protected function is_custom_meta_table_active() {
91
		return give_has_upgrade_completed( 'v20_move_metadata_into_new_table' );
92
	}
93
}
94