Completed
Push — master ( e6e2aa...27549f )
by Thomas
09:03
created

Relationships   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getModel() 0 3 1
A add() 0 9 2
A getAll() 0 3 1
A getOne() 0 3 1
A getMany() 0 3 1
A size() 0 3 1
A has() 0 3 1
A get() 0 3 1
1
<?php
2
namespace keeko\tools\model;
3
4
use phootwork\collection\Map;
5
use Propel\Generator\Model\Table;
6
7
class Relationships {
8
	
9
	/** @var Map */
10
	private $all;
11
	
12
	/** @var Map */
13
	private $one;
14
	
15
	/** @var Map */
16
	private $many;
17
	
18
	/** @var Table */
19
	private $model;
20
	
21
	public function __construct(Table $model) {
22
		$this->model = $model;
23
		$this->all = new Map();
24
		$this->one = new Map();
25
		$this->many = new Map();
26
	}
27
	
28
	/**
29
	 * @return Table
30
	 */
31
	public function getModel() {
32
		return $this->model;
33
	}
34
	
35
	/**
36
	 * Adds a relationships to this collection
37
	 * 
38
	 * @param Relationship $relationship
39
	 */
40
	public function add(Relationship $relationship) {
41
		if ($relationship instanceof ManyRelationship) {
42
			$this->many->set($relationship->getForeign()->getOriginCommonName(), $relationship);
43
		} else {
44
			$this->one->set($relationship->getForeign()->getOriginCommonName(), $relationship);
45
		}
46
		
47
		$this->all->set($relationship->getForeign()->getOriginCommonName(), $relationship);
48
	}
49
	
50
	/**
51
	 * @return Map
52
	 */
53
	public function getAll() {
54
		return $this->all;
55
	}
56
	
57
	/**
58
	 * @return Map
59
	 */
60
	public function getOne() {
61
		return $this->one;
62
	}
63
	
64
	/**
65
	 * @return Map
66
	 */
67
	public function getMany() {
68
		return $this->many;
69
	}
70
	
71
	/**
72
	 * The number of relationships
73
	 * 
74
	 * @return int
75
	 */
76
	public function size() {
77
		return $this->all->size();
78
	}
79
	
80
	/**
81
	 * Checks whether a relationship with the given foreign name exists
82
	 * 
83
	 * @param string $foreignName
84
	 * @return boolean
85
	 */
86
	public function has($foreignName) {
87
		return $this->all->has($foreignName);
88
	}
89
	
90
	/**
91
	 * Returns a relationship with the given foreign name
92
	 * 
93
	 * @param string $foreignName
94
	 * @return Relationship
95
	 */
96
	public function get($foreignName) {
97
		return $this->all->get($foreignName);
98
	}
99
}