Relationship   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 3
cbo 1
dl 0
loc 128
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
getType() 0 1 ?
A isOneToOne() 0 3 1
A getModel() 0 3 1
A getForeign() 0 3 1
A getForeignKey() 0 3 1
getRelatedName() 0 1 ?
A getRelatedPluralName() 0 3 1
A getRelatedTypeName() 0 3 1
A getRelatedPluralTypeName() 0 3 1
getReverseRelatedName() 0 1 ?
A getReverseRelatedPluralName() 0 3 1
A getReverseRelatedTypeName() 0 3 1
A getReverseRelatedPluralTypeName() 0 3 1
A isReflexive() 0 3 1
1
<?php
2
namespace keeko\tools\model;
3
4
use Propel\Generator\Model\ForeignKey;
5
use Propel\Generator\Model\Table;
6
use keeko\framework\utils\NameUtils;
7
8
abstract class Relationship {
9
10
	const ONE_TO_ONE = 'one-to-one';
11
	const ONE_TO_MANY = 'one-to-many';
12
	const MANY_TO_MANY = 'many-to-many';
13
14
	/** @var Table */
15
	protected $model;
16
17
	/** @var Table */
18
	protected $foreign;
19
20
	/** @var ForeignKey */
21
	protected $fk;
22
23
	/**
24
	 * Returns the type of this relationship
25
	 *
26
	 * @return string
27
	 */
28
	abstract public function getType();
29
30
	public function isOneToOne() {
31
		return $this->getType() == Relationship::ONE_TO_ONE;
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
32
	}
33
34
	/**
35
	 * Returns the model
36
	 *
37
	 * @return Table
38
	 */
39
	public function getModel() {
40
		return $this->model;
41
	}
42
43
	/**
44
	 * Returns the foreign model
45
	 *
46
	 * @return Table
47
	 */
48
	public function getForeign() {
49
		return $this->foreign;
50
	}
51
52
	/**
53
	 * Returns the foreign key
54
	 *
55
	 * @return ForeignKey
56
	 */
57
	public function getForeignKey() {
58
		return $this->fk;
59
	}
60
61
	/**
62
	 * Returns the related name in studly case
63
	 *
64
	 * @return string
65
	 */
66
	abstract public function getRelatedName();
67
68
	/**
69
	 * Returns the pluralized related name in studly case
70
	 *
71
	 * @return string
72
	 */
73
	public function getRelatedPluralName() {
74
		return NameUtils::pluralize($this->getRelatedName());
75
	}
76
77
	/**
78
	 * Returns the related type name for usage in api environment (slug, type-name, etc)
79
	 *
80
	 * @return string
81
	 */
82
	public function getRelatedTypeName() {
83
		return NameUtils::dasherize($this->getRelatedName());
84
	}
85
86
	/**
87
	 * Returns the pluralized related type name for usage in api environment (slug, type-name, etc)
88
	 *
89
	 * @return string
90
	 */
91
	public function getRelatedPluralTypeName() {
92
		return NameUtils::pluralize($this->getRelatedTypeName());
93
	}
94
95
	/**
96
	 * Returns the reverse related name in studly case
97
	 */
98
	abstract public function getReverseRelatedName();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
99
100
	/**
101
	 * Returns the pluralized reverse related name in studly case
102
	 *
103
	 * @return string
104
	 */
105
	public function getReverseRelatedPluralName() {
106
		return NameUtils::pluralize($this->getReverseRelatedName());
107
	}
108
109
	/**
110
	 * Returns the reverse related type name for usage in api environment (slug, type-name, etc)
111
	 *
112
	 * @return string
113
	 */
114
	public function getReverseRelatedTypeName() {
115
		return NameUtils::dasherize($this->getReverseRelatedName());
116
	}
117
118
	/**
119
	 * Returns the pluralized reverse related type name for usage in api environment (slug, type-name, etc)
120
	 *
121
	 * @return string
122
	 */
123
	public function getReverseRelatedPluralTypeName() {
124
		return NameUtils::pluralize($this->getReverseRelatedTypeName());
125
	}
126
127
	/**
128
	 * Returns whether the relationship refers to itself
129
	 *
130
	 * @return bool
131
	 */
132
	public function isReflexive() {
133
		return $this->model == $this->foreign;
134
	}
135
}