1 | <?php |
||
13 | class TableDef implements \JsonSerializable { |
||
14 | /// Properties /// |
||
15 | |||
16 | /** |
||
17 | * @var array The columns that need to be set in the table. |
||
18 | */ |
||
19 | private $columns; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | * @var string The name of the currently working table. |
||
24 | */ |
||
25 | private $table; |
||
26 | |||
27 | /** |
||
28 | * @var array An array of indexes. |
||
29 | */ |
||
30 | private $indexes; |
||
31 | |||
32 | /// Methods /// |
||
33 | |||
34 | /** |
||
35 | * Initialize an instance of the {@link TableDef} class. |
||
36 | * |
||
37 | * @param string $name The name of the table. |
||
38 | */ |
||
39 | 32 | public function __construct($name = '') { |
|
43 | |||
44 | /** |
||
45 | * Reset the internal state of this object so that it can be re-used. |
||
46 | * |
||
47 | * @return TableDef Returns $this for fluent calls. |
||
48 | */ |
||
49 | 32 | public function reset() { |
|
57 | |||
58 | /** |
||
59 | * Define a column. |
||
60 | * |
||
61 | * @param string $name The column name. |
||
62 | * @param string $type The column type. |
||
63 | * @param mixed $nullDefault Whether the column is required or it's default. |
||
64 | * |
||
65 | * null|true |
||
66 | * : The column is not required. |
||
67 | * false |
||
68 | * : The column is required. |
||
69 | * Anything else |
||
70 | * : The column is required and this is its default. |
||
71 | * @return TableDef |
||
72 | */ |
||
73 | 32 | public function setColumn($name, $type, $nullDefault = false) { |
|
78 | |||
79 | /** |
||
80 | * Get an array column def from a structured function call. |
||
81 | * |
||
82 | * @param string $dbtype The database type of the column. |
||
83 | * @param mixed $nullDefault Whether or not to allow null or the default value. |
||
84 | * |
||
85 | * null|true |
||
86 | * : The column is not required. |
||
87 | * false |
||
88 | * : The column is required. |
||
89 | * Anything else |
||
90 | * : The column is required and this is its default. |
||
91 | * |
||
92 | * @return array Returns the column def as an array. |
||
93 | */ |
||
94 | 32 | private function createColumnDef($dbtype, $nullDefault = false) { |
|
116 | |||
117 | /** |
||
118 | * Define the primary key in the database. |
||
119 | * |
||
120 | * @param string $name The name of the column. |
||
121 | * @param string $type The datatype for the column. |
||
122 | * @return TableDef |
||
123 | */ |
||
124 | 20 | public function setPrimaryKey($name, $type = 'int') { |
|
136 | |||
137 | /** |
||
138 | * Add or update an index. |
||
139 | * |
||
140 | * @param string $type One of the `Db::INDEX_*` constants. |
||
141 | * @param array $columns The columns in the index. |
||
142 | * @return $this |
||
143 | */ |
||
144 | 32 | public function addIndex($type, ...$columns) { |
|
172 | |||
173 | /** |
||
174 | * Get the table. |
||
175 | * |
||
176 | * @return string Returns the table. |
||
177 | */ |
||
178 | public function getTable() { |
||
181 | |||
182 | /** |
||
183 | * Set the name of the table. |
||
184 | * |
||
185 | * @param string|null $name The name of the table. |
||
186 | * @return TableDef|string Returns $this for fluent calls. |
||
187 | */ |
||
188 | 8 | public function setTable($name) { |
|
192 | |||
193 | /** |
||
194 | * Specify data which should be serialized to JSON. |
||
195 | * |
||
196 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
197 | * @return mixed data which can be serialized by {@link json_encode()}, |
||
198 | * which is a value of any type other than a resource. |
||
199 | */ |
||
200 | public function jsonSerialize() { |
||
203 | |||
204 | /** |
||
205 | * Get the array representation of the table definition. |
||
206 | * |
||
207 | * @return array Returns a definition array. |
||
208 | */ |
||
209 | 32 | public function toArray() { |
|
216 | |||
217 | /** |
||
218 | * Execute this table definition on a database. |
||
219 | * |
||
220 | * @param Db $db The database to query. |
||
221 | * @param array $options Additional options. See {@link Db::defineTable()}. |
||
222 | */ |
||
223 | 22 | public function exec(Db $db, array $options = []) { |
|
226 | } |
||
227 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.