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 PulseColumnSettersTestCase extends PulseUnitTestCase |
||
10 | { |
||
11 | private $userId; |
||
12 | |||
13 | /** |
||
14 | * @var Pulse |
||
15 | */ |
||
16 | private $pulse; |
||
17 | |||
18 | public static function invalidColorValueProvider() |
||
27 | |||
28 | public static function invalidTextProvider() |
||
35 | |||
36 | public static function invalidNumericProvider() |
||
45 | |||
46 | public static function invalidDateTimeProvider() |
||
55 | |||
56 | public static function invalidPersonProvider() |
||
66 | |||
67 | public static function invalidTimelineProvider() |
||
74 | |||
75 | public function setUp() |
||
82 | |||
83 | public function testSettingStatusColumn() |
||
91 | |||
92 | /** |
||
93 | * @dataProvider invalidColorValueProvider |
||
94 | */ |
||
95 | public function testSettingStatusColumnWithWrongTypes($color) |
||
101 | |||
102 | View Code Duplication | public function testSettingTextColumn() |
|
110 | |||
111 | /** |
||
112 | * @dataProvider invalidTextProvider |
||
113 | */ |
||
114 | public function testSettingTextColumnWithWrongTypes($value) |
||
120 | |||
121 | View Code Duplication | public function testSettingNumericColumn() |
|
129 | |||
130 | /** |
||
131 | * @dataProvider invalidNumericProvider |
||
132 | */ |
||
133 | public function testSettingNumericColumnWithWrongTypes($value) |
||
139 | |||
140 | public function testSettingDateColumn() |
||
148 | |||
149 | /** |
||
150 | * @dataProvider invalidDateTimeProvider |
||
151 | */ |
||
152 | public function testSettingDateColumnWithWrongTypes($value) |
||
158 | |||
159 | public function testSettingTimelineColumn() |
||
168 | |||
169 | /** |
||
170 | * @dataProvider invalidTimelineProvider |
||
171 | */ |
||
172 | public function testSettingTimelineColumnWithWrongTypes($dateOne, $dateTwo) |
||
178 | |||
179 | public function testSettingPersonColumnFromInt() |
||
186 | |||
187 | public function testSettingPersonColumnFromObject() |
||
195 | |||
196 | /** |
||
197 | * @dataProvider invalidPersonProvider |
||
198 | */ |
||
199 | public function testSettingPersonColumnWithWrongTypes($value) |
||
205 | |||
206 | public function testSettingNonExistentColumn() |
||
214 | } |
||
215 |
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.