Completed
Branch BUG-9140-has-billing-form-igno... (f963e1)
by
unknown
257:50 queued 242:55
created

EEM_Extra_Join   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6
Metric Value
wmc 1
lcom 0
cbo 6
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 24 1
1
<?php
2
3
/**
4
 *
5
 * Class EEM_Extra_Join
6
 *
7
 * Special model that can be used as a join model between any two models. This
8
 * helps prevent the addition of further tables.
9
 * This model has two foreign keys EXJ_first_model_ID and EXJ_second_model_ID.
10
 * The first always points to the model which is ALPHABETICALLY LOWER than the other 
11
 * (ie comes earlier in the alphabet). Eg if an entry in this model's table
12
 * joins an event to a venue, the event id will be in EXJ_first_model_ID, and the
13
 * venue's id will be in EXJ_seonc_model_ID.
14
 * However, if the entry in this model's table joins event to attendee,
15
 * the attendee id will be in EXJ_first_model_ID, and the event id will be in
16
 * EXJ_second_model_ID. 
17
 *
18
 * @package         Event Espresso
19
 * @subpackage    
20
 * @author				Mike Nelson
21
 * @since		 	   $VID:$
22
 *
23
 */
24
if (!defined('EVENT_ESPRESSO_VERSION')) {
25
	exit('No direct script access allowed');
26
}
27
28
class EEM_Extra_Join extends EEM_Base{
29
	// private instance of the Extra Join object
30
	protected static $_instance = NULL;
31
	
32
	public function __construct($timezone = NULL) {
33
		$models_this_can_join = array_keys( EE_Registry::instance()->non_abstract_db_models );
34
		$this->_tables = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Extra_Join' => ne...extra_join', 'EXJ_ID')) of type array<string,object<EE_P...ct<EE_Primary_Table>"}> is incompatible with the declared type array<integer,object<EE_Table_Base>> of property $_tables.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
			'Extra_Join' => new EE_Primary_Table( 'esp_extra_join', 'EXJ_ID' ),
36
		);
37
		$this->_fields = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Extra_Join' => ar...models_this_can_join))) of type array<string,array<strin...odel_Name_Field>\"}>"}> is incompatible with the declared type array<integer,object<EE_Model_Field_Base>> of property $_fields.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
			'Extra_Join' => array(
39
				'EXJ_ID' => new EE_Primary_Key_Int_Field( 'EXJ_ID', __( 'Extra Join ID', 'event_espresso' ) ),
40
				'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field( 'EXJ_first_model_ID', __( 'First Model ID', 'event_espresso' ), true, 0, $models_this_can_join ),
0 ignored issues
show
Documentation introduced by
$models_this_can_join is of type array<integer,integer|string>, but the function expects a string.

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...
41
				'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field( 'EXJ_first_model_name', __( 'First Model Name', 'event_espresso'), true, '', $models_this_can_join ),
0 ignored issues
show
Documentation introduced by
$models_this_can_join is of type array<integer,integer|string>, but the function expects a string.

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...
42
				'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field( 'EXJ_second_model_ID', __( 'Second Model ID', 'event_espresso' ), true, 0, $models_this_can_join ),
0 ignored issues
show
Documentation introduced by
$models_this_can_join is of type array<integer,integer|string>, but the function expects a string.

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...
43
				'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field( 'EXJ_second_model_name', __( 'Second Model Name', 'event_espresso'), true, '', $models_this_can_join ),
0 ignored issues
show
Documentation introduced by
$models_this_can_join is of type array<integer,integer|string>, but the function expects a string.

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...
44
				
45
			)
46
		);
47
		//this model is weird in that it has two foreign key columns which can point to any model/table.
48
		//eg a foreign key to event will be in "EXJ_first_model_ID", provided the other
49
		//model linked to is alphabetically greater than event (eg venue).
50
		//but if the model linked to is alphabetically lower (eg attendee), 
51
		//the foreign key to the event will be in "EXJ_second_model_ID"
52
		//so normal usage of foreign keys is weird. So don't define any
53
		//relations to other models because they won't work properly with this model
54
		parent::__construct($timezone);
55
	}
56
}
57