Completed
Push — master ( 118f52...c5048d )
by Thomas
10:09
created

OneToOneRelationship::setReverseRelationship()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
namespace keeko\tools\model;
3
4
use Propel\Generator\Model\ForeignKey;
5
use Propel\Generator\Model\Table;
6
7
class OneToOneRelationship extends Relationship {
8
9
	/** @var OneToOneRelationship */
10
	protected $reverse;
11
12
	/** @var OneToOneRelationship */
13
	private $defined;
14
15
	public function __construct(Table $model, Table $foreign, ForeignKey $fk) {
16
		$this->model = $model;
17
		$this->foreign = $foreign;
18
		$this->fk = $fk;
19
	}
20
21
	public function getType() {
22
		return self::ONE_TO_ONE;
23
	}
24
25
	public function getRelatedName() {
26
		$relatedName = $this->fk->getPhpName();
27
		if (empty($relatedName)) {
28
			$relatedName = $this->foreign->getPhpName();
29
		}
30
31
		return $relatedName;
32
	}
33
34
	public function getReverseRelatedName() {
35
		$reverseRelatedName = $this->fk->getRefPhpName();
36
		if (empty($reverseRelatedName)) {
37
			$reverseRelatedName = $this->model->getPhpName();
38
		}
39
40
		return $reverseRelatedName;
41
	}
42
43
	/**
44
	 * Return the reverse relationship
45
	 *
46
	 * @return Relationship
47
	 */
48
	public function getReverseRelationship() {
49
		return $this->reverse;
50
	}
51
52
	public function setReverseRelationship(OneToOneRelationship $relationship) {
53
		if ($this->reverse != $relationship) {
54
			$this->reverse = $relationship;
55
			$this->reverse->setDefinedRelationship($this);
56
		}
57
	}
58
59
	public function getDefinedRelationship() {
60
		return $this->defined;
61
	}
62
63
	public function setDefinedRelationship(OneToOneRelationship $relationship) {
64
		if ($this->defined != $relationship) {
65
			$this->defined = $relationship;
66
			$this->defined->setReverseRelationship($this);
67
		}
68
	}
69
}