Completed
Push — master ( c7b947...966759 )
by Thomas
08:09
created

ManyToManyRelationship   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 2
cbo 4
dl 0
loc 78
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 4
A getType() 0 3 1
A getMiddle() 0 3 1
A getCrossForeignKeys() 0 3 1
A getLocalKey() 0 3 1
A getRelatedName() 0 8 2
A getReverseRelatedName() 0 8 2
1
<?php
2
namespace keeko\tools\model;
3
4
use Propel\Generator\Model\CrossForeignKeys;
5
use Propel\Generator\Model\ForeignKey;
6
use Propel\Generator\Model\Table;
7
8
class ManyToManyRelationship extends Relationship {
9
	
10
	/** @var ForeignKey */
11
	protected $lk;
12
	
13
	/** @var CrossForeignKeys */
14
	protected $cfk;
15
	
16
	public function __construct(Table $model, CrossForeignKeys $cfk) {
17
		$this->model = $model;
18
		$this->cfk = $cfk;
19
		
20
		foreach ($cfk->getMiddleTable()->getForeignKeys() as $fk) {
21
			if ($fk->getForeignTable() != $model) {
22
				$this->fk = $fk;
23
			} else if ($fk->getForeignTable() == $model) {
24
				$this->lk = $fk;
25
			}
26
		}
27
		
28
		$this->foreign = $this->fk->getForeignTable();
29
	}
30
	
31
	/**
32
	 * Returns the type of this relationship
33
	 *
34
	 * @return string
35
	 */
36
	public function getType() {
37
		return self::MANY_TO_MANY;
38
	}
39
	
40
	/**
41
	 * Returns the middle table
42
	 * 
43
	 * @return Table
44
	 */
45
	public function getMiddle() {
46
		return $this->cfk->getMiddleTable();
47
	}
48
	
49
	/**
50
	 * Returns the cross foreign keys
51
	 * 
52
	 * @return CrossForeignKeys
53
	 */
54
	public function getCrossForeignKeys() {
55
		return $this->cfk;
56
	}
57
	
58
	/**
59
	 * Returns the local key
60
	 * 
61
	 * @return ForeignKey
62
	 */
63
	public function getLocalKey() {
64
		return $this->lk;
65
	}
66
	
67
	public function getRelatedName() {
68
		$relatedName = $this->lk->getRefPhpName();
69
		if (empty($relatedName)) {
70
			$relatedName = $this->foreign->getPhpName();
71
		}
72
		
73
		return $relatedName;
74
	}
75
	
76
	public function getReverseRelatedName() {
77
		$reverseRelatedName = $this->lk->getPhpName();
78
		if (empty($reverseRelatedName)) {
79
			$reverseRelatedName = $this->model->getPhpName();
80
		}
81
	
82
		return $reverseRelatedName;
83
	}
84
85
}
86