Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
33 | class DynamicModelSeederTaskTest extends CakeTestCase { |
||
34 | |||
35 | /** |
||
36 | * The task under test |
||
37 | * |
||
38 | * @var null|TestDynamicModelSeederTask |
||
39 | */ |
||
40 | protected $_task = null; |
||
41 | |||
42 | /** |
||
43 | * Setup the shell under test |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | View Code Duplication | public function setUp() { |
|
54 | |||
55 | /** |
||
56 | * Creates a shell mock |
||
57 | * |
||
58 | * @param array $methods A list of methods to mock. |
||
59 | * @param string $className Optional name of the seeder shell class to mock. |
||
60 | * @return void |
||
61 | */ |
||
62 | View Code Duplication | protected function _createShellMock($methods, $className = 'TestDynamicModelSeederTask') { |
|
71 | |||
72 | /** |
||
73 | * Tests the _getModelName method |
||
74 | * |
||
75 | * @return void |
||
76 | * @covers ::getModelName |
||
77 | */ |
||
78 | public function testGetModelName() { |
||
83 | |||
84 | /** |
||
85 | * Tests the _fieldFormatters method |
||
86 | * |
||
87 | * @return void |
||
88 | * @covers ::fieldFormatters |
||
89 | */ |
||
90 | public function testFieldFormatters() { |
||
95 | |||
96 | /** |
||
97 | * Tests the _getSeedingMode method |
||
98 | * |
||
99 | * @return void |
||
100 | * @covers ::getSeedingMode |
||
101 | */ |
||
102 | public function testGetSeedingMode() { |
||
106 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.