|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rentgen\Database; |
|
4
|
|
|
|
|
5
|
|
|
use Rentgen\Database\Constraint\ConstraintInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Arek Jaskólski <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
class Table implements DatabaseObjectInterface |
|
11
|
|
|
{ |
|
12
|
|
|
private $name; |
|
13
|
|
|
private $schema; |
|
14
|
|
|
private $description; |
|
15
|
|
|
protected $columns = array(); |
|
16
|
|
|
protected $constraints = array(); |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param string $name Table name. |
|
22
|
|
|
* @param Schema $schem Schema instance. |
|
|
|
|
|
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct($name, Schema $schema = null) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->name = $name; |
|
27
|
|
|
$this->schema = null === $schema ? new Schema() : $schema; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get table name. |
|
32
|
|
|
* |
|
33
|
|
|
* @return string Table name. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getName() |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->name; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get qualified name (schema name + table name) |
|
42
|
|
|
* |
|
43
|
|
|
* @return string Qualified name. |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getQualifiedName() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->schema->getName() . '.' .$this->name; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Add column to table. |
|
52
|
|
|
* |
|
53
|
|
|
* @param Column $column Column instance. |
|
54
|
|
|
* |
|
55
|
|
|
* @return Table Table instance. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function addColumn(Column $column) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->columns[] = $column; |
|
60
|
|
|
|
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get columns of table. |
|
66
|
|
|
* |
|
67
|
|
|
* @return Column[] Array of Column instances. |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getColumns() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->columns; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get column of table. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $name Column name. |
|
78
|
|
|
* |
|
79
|
|
|
* @return Column Column instance. |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getColumn($name) |
|
82
|
|
|
{ |
|
83
|
|
|
foreach ($this->columns as $column) { |
|
84
|
|
|
if ($column->getName() == $name) { |
|
85
|
|
|
return $column; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return null; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Add contraint to table. |
|
94
|
|
|
* |
|
95
|
|
|
* @param ConstraintInterface $constraint Instance of class implements ConstraintInterface. |
|
96
|
|
|
* |
|
97
|
|
|
* @return Table Table instance. |
|
98
|
|
|
*/ |
|
99
|
|
|
public function addConstraint(ConstraintInterface $constraint) |
|
100
|
|
|
{ |
|
101
|
|
|
$constraint->setTable($this); |
|
102
|
|
|
$this->constraints[] = $constraint; |
|
103
|
|
|
|
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Get constraints of table. |
|
109
|
|
|
* |
|
110
|
|
|
* @return ConstraintInterface[] Array of instances implement ConstraintInterface. |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getConstraints() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->constraints; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Set schema name. |
|
119
|
|
|
* |
|
120
|
|
|
* @param string $name Schama name. |
|
|
|
|
|
|
121
|
|
|
*/ |
|
122
|
|
|
public function setSchema(Schema $schema) |
|
123
|
|
|
{ |
|
124
|
|
|
$this->schema = $schema; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getSchema() |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->schema; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Set table description. |
|
134
|
|
|
* |
|
135
|
|
|
* @param string $description Table description. |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setDescription($description) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->description = $description; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get table description. |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getDescription() |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->description; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.