Conditions | 1 |
Paths | 1 |
Total Lines | 160 |
Code Lines | 121 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
173 | public function testColumnComments() |
||
174 | { |
||
175 | $table = new Table('sqlsrv_column_comment'); |
||
176 | $table->addColumn('id', 'integer', ['autoincrement' => true]); |
||
177 | $table->addColumn('comment_null', 'integer', ['comment' => null]); |
||
178 | $table->addColumn('comment_false', 'integer', ['comment' => false]); |
||
179 | $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); |
||
180 | $table->addColumn('comment_integer_0', 'integer', ['comment' => 0]); |
||
181 | $table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]); |
||
182 | $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); |
||
183 | $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); |
||
184 | $table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']); |
||
185 | $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); |
||
186 | $table->addColumn('commented_type', 'object'); |
||
187 | $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); |
||
188 | $table->setPrimaryKey(['id']); |
||
189 | |||
190 | $this->schemaManager->createTable($table); |
||
191 | |||
192 | $columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment'); |
||
193 | self::assertCount(12, $columns); |
||
194 | self::assertNull($columns['id']->getComment()); |
||
195 | self::assertNull($columns['comment_null']->getComment()); |
||
196 | self::assertNull($columns['comment_false']->getComment()); |
||
197 | self::assertNull($columns['comment_empty_string']->getComment()); |
||
198 | self::assertEquals('0', $columns['comment_integer_0']->getComment()); |
||
199 | self::assertEquals('0', $columns['comment_float_0']->getComment()); |
||
200 | self::assertEquals('0', $columns['comment_string_0']->getComment()); |
||
201 | self::assertEquals('Doctrine 0wnz you!', $columns['comment']->getComment()); |
||
202 | self::assertEquals('Doctrine 0wnz comments for explicitly quoted columns!', $columns['comment_quoted']->getComment()); |
||
203 | self::assertEquals('Doctrine 0wnz comments for reserved keyword columns!', $columns['[create]']->getComment()); |
||
204 | self::assertNull($columns['commented_type']->getComment()); |
||
205 | self::assertEquals('Doctrine array type.', $columns['commented_type_with_comment']->getComment()); |
||
206 | |||
207 | $tableDiff = new TableDiff('sqlsrv_column_comment'); |
||
208 | $tableDiff->fromTable = $table; |
||
209 | $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); |
||
210 | $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), ['comment' => null]); |
||
211 | $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), ['comment' => false]); |
||
212 | $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']); |
||
213 | $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), ['comment' => 0]); |
||
214 | $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), ['comment' => 0.0]); |
||
215 | $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), ['comment' => '0']); |
||
216 | $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), ['comment' => 'Doctrine']); |
||
217 | $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), ['comment' => 'rulez']); |
||
218 | $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), ['comment' => '666']); |
||
219 | $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); |
||
220 | $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), ['comment' => '666']); |
||
221 | |||
222 | $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), ['comment' => 'Double for real!']); |
||
223 | |||
224 | // Add comment to non-commented column. |
||
225 | $tableDiff->changedColumns['id'] = new ColumnDiff( |
||
226 | 'id', |
||
227 | new Column('id', Type::getType('integer'), ['autoincrement' => true, 'comment' => 'primary']), |
||
228 | ['comment'], |
||
229 | new Column('id', Type::getType('integer'), ['autoincrement' => true]) |
||
230 | ); |
||
231 | |||
232 | // Remove comment from null-commented column. |
||
233 | $tableDiff->changedColumns['comment_null'] = new ColumnDiff( |
||
234 | 'comment_null', |
||
235 | new Column('comment_null', Type::getType('string')), |
||
236 | ['type'], |
||
237 | new Column('comment_null', Type::getType('integer'), ['comment' => null]) |
||
238 | ); |
||
239 | |||
240 | // Add comment to false-commented column. |
||
241 | $tableDiff->changedColumns['comment_false'] = new ColumnDiff( |
||
242 | 'comment_false', |
||
243 | new Column('comment_false', Type::getType('integer'), ['comment' => 'false']), |
||
244 | ['comment'], |
||
245 | new Column('comment_false', Type::getType('integer'), ['comment' => false]) |
||
246 | ); |
||
247 | |||
248 | // Change type to custom type from empty string commented column. |
||
249 | $tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff( |
||
250 | 'comment_empty_string', |
||
251 | new Column('comment_empty_string', Type::getType('object')), |
||
252 | ['type'], |
||
253 | new Column('comment_empty_string', Type::getType('integer'), ['comment' => '']) |
||
254 | ); |
||
255 | |||
256 | // Change comment to false-comment from zero-string commented column. |
||
257 | $tableDiff->changedColumns['comment_string_0'] = new ColumnDiff( |
||
258 | 'comment_string_0', |
||
259 | new Column('comment_string_0', Type::getType('integer'), ['comment' => false]), |
||
260 | ['comment'], |
||
261 | new Column('comment_string_0', Type::getType('integer'), ['comment' => '0']) |
||
262 | ); |
||
263 | |||
264 | // Remove comment from regular commented column. |
||
265 | $tableDiff->changedColumns['comment'] = new ColumnDiff( |
||
266 | 'comment', |
||
267 | new Column('comment', Type::getType('integer')), |
||
268 | ['comment'], |
||
269 | new Column('comment', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) |
||
270 | ); |
||
271 | |||
272 | // Change comment and change type to custom type from regular commented column. |
||
273 | $tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff( |
||
274 | '`comment_quoted`', |
||
275 | new Column('`comment_quoted`', Type::getType('array'), ['comment' => 'Doctrine array.']), |
||
276 | ['comment', 'type'], |
||
277 | new Column('`comment_quoted`', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) |
||
278 | ); |
||
279 | |||
280 | // Remove comment and change type to custom type from regular commented column. |
||
281 | $tableDiff->changedColumns['create'] = new ColumnDiff( |
||
282 | 'create', |
||
283 | new Column('create', Type::getType('object')), |
||
284 | ['comment', 'type'], |
||
285 | new Column('create', Type::getType('integer'), ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']) |
||
286 | ); |
||
287 | |||
288 | // Add comment and change custom type to regular type from non-commented column. |
||
289 | $tableDiff->changedColumns['commented_type'] = new ColumnDiff( |
||
290 | 'commented_type', |
||
291 | new Column('commented_type', Type::getType('integer'), ['comment' => 'foo']), |
||
292 | ['comment', 'type'], |
||
293 | new Column('commented_type', Type::getType('object')) |
||
294 | ); |
||
295 | |||
296 | // Remove comment from commented custom type column. |
||
297 | $tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff( |
||
298 | 'commented_type_with_comment', |
||
299 | new Column('commented_type_with_comment', Type::getType('array')), |
||
300 | ['comment'], |
||
301 | new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.']) |
||
302 | ); |
||
303 | |||
304 | $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]); |
||
305 | |||
306 | $this->schemaManager->alterTable($tableDiff); |
||
307 | |||
308 | $columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment'); |
||
309 | self::assertCount(23, $columns); |
||
310 | self::assertEquals('primary', $columns['id']->getComment()); |
||
311 | self::assertNull($columns['comment_null']->getComment()); |
||
312 | self::assertEquals('false', $columns['comment_false']->getComment()); |
||
313 | self::assertNull($columns['comment_empty_string']->getComment()); |
||
314 | self::assertEquals('0', $columns['comment_double_0']->getComment()); |
||
315 | self::assertNull($columns['comment_string_0']->getComment()); |
||
316 | self::assertNull($columns['comment']->getComment()); |
||
317 | self::assertEquals('Doctrine array.', $columns['comment_quoted']->getComment()); |
||
318 | self::assertNull($columns['[create]']->getComment()); |
||
319 | self::assertEquals('foo', $columns['commented_type']->getComment()); |
||
320 | self::assertNull($columns['commented_type_with_comment']->getComment()); |
||
321 | self::assertNull($columns['added_comment_none']->getComment()); |
||
322 | self::assertNull($columns['added_comment_null']->getComment()); |
||
323 | self::assertNull($columns['added_comment_false']->getComment()); |
||
324 | self::assertNull($columns['added_comment_empty_string']->getComment()); |
||
325 | self::assertEquals('0', $columns['added_comment_integer_0']->getComment()); |
||
326 | self::assertEquals('0', $columns['added_comment_float_0']->getComment()); |
||
327 | self::assertEquals('0', $columns['added_comment_string_0']->getComment()); |
||
328 | self::assertEquals('Doctrine', $columns['added_comment']->getComment()); |
||
329 | self::assertEquals('rulez', $columns['added_comment_quoted']->getComment()); |
||
330 | self::assertEquals('666', $columns['[select]']->getComment()); |
||
331 | self::assertNull($columns['added_commented_type']->getComment()); |
||
332 | self::assertEquals('666', $columns['added_commented_type_with_comment']->getComment()); |
||
333 | } |
||
366 |