TableRelation   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 63
rs 10
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 24 1
1
<?php
2
namespace samson\activerecord;
3
4
/**
5
 * Class for defining permanent relations beetween database tables
6
 * @author Vitaly Iegorov <[email protected]>
7
 *
8
 */
9
class TableRelation 
10
{
11
	/** Relation type: one-to-many */
12
	const T_ONE_TO_MANY = 1;
13
	/** Relation type: one-to-one */
14
	const T_ONE_TO_ONE = 0;
15
	
16
	/**	Collection of permanent instances of class */
17
	public static $instances = array();
18
	
19
	/** Parent table in relation */
20
	public $parent;
21
	
22
	/** Child table in relation */
23
	public $child;
24
	
25
	/** Parent table field name in relation */
26
	public $parent_field;
27
	
28
	/** Child table field name in relation */
29
	public $child_field;
30
	
31
	/** Alias for JOIN in relation */
32
	public $alias;
33
	
34
	/** Relation type */
35
	public $type;
36
	
37
	/**
38
	 * Constructor 
39
	 * 
40
	 * @param string 	$p		Parent table name
41
	 * @param string 	$c		Child table name
42
	 * @param string 	$pf		Parent field name
43
	 * @param integer 	$rt		Relation type 
44
	 * @param string 	$cf		Child field name
45
	 * @param string 	$a		Alias	 
46
	 */
47
	public function __construct( $p, $c, $pf = null,  $rt = self::T_ONE_TO_ONE, $cf = null, $a = null )
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between opening bracket and argument "$p"; 1 found
Loading history...
Coding Style introduced by
Expected 1 space between comma and argument "$rt"; 2 found
Loading history...
Coding Style introduced by
Expected 0 spaces between argument "$a" and closing bracket; 1 found
Loading history...
48
	{
49
		// Set table relation parameters 
50
		$this->parent = $p;
51
		$this->child = $c; 
52
		$this->alias = $a;
53
		$this->type = $rt;		
54
		$this->parent_field = $pf;
55
		$this->child_field = $cf;
56
		
57
		/*
58
		// Get primary field
59
		eval('$primary = '.$p.'::$_primary;');
60
		
61
		// If no primary field is specified - set parent primary field
62
		if( !isset($pf) ) $this->parent_field = $p.'.'.$primary;
63
		
64
		// If no child field is specified - set parent primary field
65
		if( !isset($cf) ) $this->child_field = $c.'.'.$primary;		
66
		*/
67
		
68
		// Save instance to static array
69
		self::$instances[] = & $this;
70
	}
71
}