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

Relationship::getRelatedName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
namespace keeko\tools\model;
3
4
use Propel\Generator\Model\Table;
5
use Propel\Generator\Model\ForeignKey;
6
use keeko\framework\utils\NameUtils;
7
8
class Relationship {
9
	
10
	/** @var Table */
11
	protected $model;
12
	
13
	/** @var Table */
14
	protected $foreign;
15
	
16
	/** @var ForeignKey */
17
	protected $fk;
18
	
19
	public function __construct(Table $model, Table $foreign, ForeignKey $fk) {
20
		$this->model = $model;
21
		$this->foreign = $foreign;
22
		$this->fk = $fk;
23
	}
24
	
25
	/**
26
	 * Returns the type of this relationship
27
	 * 
28
	 * @return string
29
	 */
30
	public function getType() {
31
		return 'one';
32
	}
33
34
	/**
35
	 *
36
	 * @return Table
37
	 */
38
	public function getModel() {
39
		return $this->model;
40
	}
41
42
	/**
43
	 *
44
	 * @return Table
45
	 */
46
	public function getForeign() {
47
		return $this->foreign;
48
	}
49
50
	/**
51
	 *
52
	 * @return ForeignKey
53
	 */
54
	public function getForeignKey() {
55
		return $this->fk;
56
	}
57
	
58
	/**
59
	 * Returns the related name in studly case
60
	 * 
61
	 * @return string
62
	 */
63
	public function getRelatedName() {
64
		$relatedName = $this->fk->getPhpName();
65
		if ($relatedName === null) {
66
			$relatedName = $this->foreign->getPhpName();
67
		}
68
		
69
		return $relatedName;
70
	}
71
	
72
	/**
73
	 * Returns the related name for using in api environment (slug, type-name, etc)
74
	 * 
75
	 * @return string
76
	 */
77
	public function getRelatedTypeName() {
78
		return NameUtils::dasherize($this->getRelatedName());
79
	}
80
}