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 |
||
9 | class TdbmFluidTableTest extends TestCase |
||
10 | { |
||
11 | View Code Duplication | public function testColumn() |
|
|
|||
12 | { |
||
13 | $schema = new Schema(); |
||
14 | $fluid = new TdbmFluidSchema($schema); |
||
15 | |||
16 | $posts = $fluid->table('posts'); |
||
17 | |||
18 | $column = $posts->column('foo'); |
||
19 | |||
20 | $this->assertTrue($schema->getTable('posts')->hasColumn('foo')); |
||
21 | |||
22 | $this->assertSame($column, $posts->column('foo'), 'Failed asserting that the same instance is returned.'); |
||
23 | } |
||
24 | |||
25 | public function testExistingColumn() |
||
38 | |||
39 | public function testIndex() |
||
50 | |||
51 | public function testUnique() |
||
62 | |||
63 | View Code Duplication | public function testPrimaryKey() |
|
75 | |||
76 | public function testId() |
||
77 | { |
||
78 | $schema = new Schema(); |
||
79 | $fluid = new TdbmFluidSchema($schema); |
||
80 | |||
81 | $posts = $fluid->table('posts'); |
||
82 | |||
83 | $posts->id(); |
||
84 | |||
85 | $this->assertTrue($schema->getTable('posts')->hasPrimaryKey()); |
||
86 | $this->assertTrue($schema->getTable('posts')->hasColumn('id')); |
||
87 | } |
||
88 | |||
89 | View Code Duplication | public function testUuid() |
|
102 | |||
103 | public function testUuidBadType() |
||
113 | |||
114 | public function testCustomBeanName() |
||
115 | { |
||
116 | $schema = new Schema(); |
||
117 | $fluid = new TdbmFluidSchema($schema); |
||
118 | |||
119 | $posts = $fluid->table('posts'); |
||
120 | |||
121 | $posts->customBeanName('Article'); |
||
122 | |||
123 | $this->assertSame("\n@Bean(name = \"Article\")", $schema->getTable('posts')->getOptions()['comment']); |
||
124 | } |
||
125 | |||
126 | View Code Duplication | public function testImplementsInterface() |
|
138 | |||
139 | public function testImplementsInterfaceOnDao() |
||
140 | { |
||
141 | $schema = new Schema(); |
||
142 | $fluid = new TdbmFluidSchema($schema); |
||
143 | |||
144 | $posts = $fluid->table('posts'); |
||
145 | |||
146 | $posts->implementsInterfaceOnDao('Foo\\Bar'); |
||
147 | |||
148 | $this->assertSame("\n@AddInterfaceOnDao(name = \"Foo\\Bar\")", $schema->getTable('posts')->getOptions()['comment']); |
||
149 | } |
||
150 | |||
151 | View Code Duplication | public function testUseTrait() |
|
163 | |||
164 | public function testUseTraitOnDao() |
||
165 | { |
||
166 | $schema = new Schema(); |
||
167 | $fluid = new TdbmFluidSchema($schema); |
||
168 | |||
169 | $posts = $fluid->table('posts'); |
||
170 | |||
171 | $posts->useTraitOnDao('Foo\\Bar'); |
||
172 | |||
173 | $this->assertSame("\n@AddTraitOnDao(name = \"Foo\\Bar\", modifiers = {})", $schema->getTable('posts')->getOptions()['comment']); |
||
174 | } |
||
175 | |||
176 | View Code Duplication | public function testTimestamps() |
|
192 | |||
193 | View Code Duplication | public function testInherits() |
|
213 | |||
214 | public function testGetDbalTable() |
||
222 | } |
||
223 |
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.