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 |
||
177 | public function testColumnComments() |
||
178 | { |
||
179 | $table = new Table('sqlsrv_column_comment'); |
||
180 | $table->addColumn('id', 'integer', array('autoincrement' => true)); |
||
181 | $table->addColumn('comment_null', 'integer', array('comment' => null)); |
||
182 | $table->addColumn('comment_false', 'integer', array('comment' => false)); |
||
183 | $table->addColumn('comment_empty_string', 'integer', array('comment' => '')); |
||
184 | $table->addColumn('comment_integer_0', 'integer', array('comment' => 0)); |
||
185 | $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); |
||
186 | $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); |
||
187 | $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); |
||
188 | $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); |
||
189 | $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); |
||
190 | $table->addColumn('commented_type', 'object'); |
||
191 | $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); |
||
192 | $table->setPrimaryKey(array('id')); |
||
193 | |||
194 | $this->_sm->createTable($table); |
||
195 | |||
196 | $columns = $this->_sm->listTableColumns("sqlsrv_column_comment"); |
||
197 | self::assertCount(12, $columns); |
||
198 | self::assertNull($columns['id']->getComment()); |
||
199 | self::assertNull($columns['comment_null']->getComment()); |
||
200 | self::assertNull($columns['comment_false']->getComment()); |
||
201 | self::assertNull($columns['comment_empty_string']->getComment()); |
||
202 | self::assertEquals('0', $columns['comment_integer_0']->getComment()); |
||
203 | self::assertEquals('0', $columns['comment_float_0']->getComment()); |
||
204 | self::assertEquals('0', $columns['comment_string_0']->getComment()); |
||
205 | self::assertEquals('Doctrine 0wnz you!', $columns['comment']->getComment()); |
||
206 | self::assertEquals('Doctrine 0wnz comments for explicitly quoted columns!', $columns['comment_quoted']->getComment()); |
||
207 | self::assertEquals('Doctrine 0wnz comments for reserved keyword columns!', $columns['[create]']->getComment()); |
||
208 | self::assertNull($columns['commented_type']->getComment()); |
||
209 | self::assertEquals('Doctrine array type.', $columns['commented_type_with_comment']->getComment()); |
||
210 | |||
211 | $tableDiff = new TableDiff('sqlsrv_column_comment'); |
||
212 | $tableDiff->fromTable = $table; |
||
213 | $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); |
||
214 | $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), array('comment' => null)); |
||
215 | $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), array('comment' => false)); |
||
216 | $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), array('comment' => '')); |
||
217 | $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), array('comment' => 0)); |
||
218 | $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), array('comment' => 0.0)); |
||
219 | $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), array('comment' => '0')); |
||
220 | $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), array('comment' => 'Doctrine')); |
||
221 | $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), array('comment' => 'rulez')); |
||
222 | $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), array('comment' => '666')); |
||
223 | $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); |
||
224 | $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), array('comment' => '666')); |
||
225 | |||
226 | $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), array('comment' => 'Double for real!')); |
||
227 | |||
228 | // Add comment to non-commented column. |
||
229 | $tableDiff->changedColumns['id'] = new ColumnDiff( |
||
230 | 'id', |
||
231 | new Column('id', Type::getType('integer'), array('autoincrement' => true, 'comment' => 'primary')), |
||
232 | array('comment'), |
||
233 | new Column('id', Type::getType('integer'), array('autoincrement' => true)) |
||
234 | ); |
||
235 | |||
236 | // Remove comment from null-commented column. |
||
237 | $tableDiff->changedColumns['comment_null'] = new ColumnDiff( |
||
238 | 'comment_null', |
||
239 | new Column('comment_null', Type::getType('string')), |
||
240 | array('type'), |
||
241 | new Column('comment_null', Type::getType('integer'), array('comment' => null)) |
||
242 | ); |
||
243 | |||
244 | // Add comment to false-commented column. |
||
245 | $tableDiff->changedColumns['comment_false'] = new ColumnDiff( |
||
246 | 'comment_false', |
||
247 | new Column('comment_false', Type::getType('integer'), array('comment' => 'false')), |
||
248 | array('comment'), |
||
249 | new Column('comment_false', Type::getType('integer'), array('comment' => false)) |
||
250 | ); |
||
251 | |||
252 | // Change type to custom type from empty string commented column. |
||
253 | $tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff( |
||
254 | 'comment_empty_string', |
||
255 | new Column('comment_empty_string', Type::getType('object')), |
||
256 | array('type'), |
||
257 | new Column('comment_empty_string', Type::getType('integer'), array('comment' => '')) |
||
258 | ); |
||
259 | |||
260 | // Change comment to false-comment from zero-string commented column. |
||
261 | $tableDiff->changedColumns['comment_string_0'] = new ColumnDiff( |
||
262 | 'comment_string_0', |
||
263 | new Column('comment_string_0', Type::getType('integer'), array('comment' => false)), |
||
264 | array('comment'), |
||
265 | new Column('comment_string_0', Type::getType('integer'), array('comment' => '0')) |
||
266 | ); |
||
267 | |||
268 | // Remove comment from regular commented column. |
||
269 | $tableDiff->changedColumns['comment'] = new ColumnDiff( |
||
270 | 'comment', |
||
271 | new Column('comment', Type::getType('integer')), |
||
272 | array('comment'), |
||
273 | new Column('comment', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) |
||
274 | ); |
||
275 | |||
276 | // Change comment and change type to custom type from regular commented column. |
||
277 | $tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff( |
||
278 | '`comment_quoted`', |
||
279 | new Column('`comment_quoted`', Type::getType('array'), array('comment' => 'Doctrine array.')), |
||
280 | array('comment', 'type'), |
||
281 | new Column('`comment_quoted`', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) |
||
282 | ); |
||
283 | |||
284 | // Remove comment and change type to custom type from regular commented column. |
||
285 | $tableDiff->changedColumns['create'] = new ColumnDiff( |
||
286 | 'create', |
||
287 | new Column('create', Type::getType('object')), |
||
288 | array('comment', 'type'), |
||
289 | new Column('create', Type::getType('integer'), array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')) |
||
290 | ); |
||
291 | |||
292 | // Add comment and change custom type to regular type from non-commented column. |
||
293 | $tableDiff->changedColumns['commented_type'] = new ColumnDiff( |
||
294 | 'commented_type', |
||
295 | new Column('commented_type', Type::getType('integer'), array('comment' => 'foo')), |
||
296 | array('comment', 'type'), |
||
297 | new Column('commented_type', Type::getType('object')) |
||
298 | ); |
||
299 | |||
300 | // Remove comment from commented custom type column. |
||
301 | $tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff( |
||
302 | 'commented_type_with_comment', |
||
303 | new Column('commented_type_with_comment', Type::getType('array')), |
||
304 | array('comment'), |
||
305 | new Column('commented_type_with_comment', Type::getType('array'), array('comment' => 'Doctrine array type.')) |
||
306 | ); |
||
307 | |||
308 | $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), array('comment' => 0)); |
||
309 | |||
310 | $this->_sm->alterTable($tableDiff); |
||
311 | |||
312 | $columns = $this->_sm->listTableColumns("sqlsrv_column_comment"); |
||
313 | self::assertCount(23, $columns); |
||
314 | self::assertEquals('primary', $columns['id']->getComment()); |
||
315 | self::assertNull($columns['comment_null']->getComment()); |
||
316 | self::assertEquals('false', $columns['comment_false']->getComment()); |
||
317 | self::assertNull($columns['comment_empty_string']->getComment()); |
||
318 | self::assertEquals('0', $columns['comment_double_0']->getComment()); |
||
319 | self::assertNull($columns['comment_string_0']->getComment()); |
||
320 | self::assertNull($columns['comment']->getComment()); |
||
321 | self::assertEquals('Doctrine array.', $columns['comment_quoted']->getComment()); |
||
322 | self::assertNull($columns['[create]']->getComment()); |
||
323 | self::assertEquals('foo', $columns['commented_type']->getComment()); |
||
324 | self::assertNull($columns['commented_type_with_comment']->getComment()); |
||
325 | self::assertNull($columns['added_comment_none']->getComment()); |
||
326 | self::assertNull($columns['added_comment_null']->getComment()); |
||
327 | self::assertNull($columns['added_comment_false']->getComment()); |
||
328 | self::assertNull($columns['added_comment_empty_string']->getComment()); |
||
329 | self::assertEquals('0', $columns['added_comment_integer_0']->getComment()); |
||
330 | self::assertEquals('0', $columns['added_comment_float_0']->getComment()); |
||
331 | self::assertEquals('0', $columns['added_comment_string_0']->getComment()); |
||
332 | self::assertEquals('Doctrine', $columns['added_comment']->getComment()); |
||
333 | self::assertEquals('rulez', $columns['added_comment_quoted']->getComment()); |
||
334 | self::assertEquals('666', $columns['[select]']->getComment()); |
||
335 | self::assertNull($columns['added_commented_type']->getComment()); |
||
336 | self::assertEquals('666', $columns['added_commented_type_with_comment']->getComment()); |
||
337 | } |
||
365 |