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 |
||
7 | class ArrayFlattenTest extends \PHPUnit_Framework_TestCase |
||
8 | { |
||
9 | /** |
||
10 | * @test |
||
11 | */ |
||
12 | public function it_flattens_an_array() |
||
19 | |||
20 | /** |
||
21 | * @test |
||
22 | */ |
||
23 | public function it_recursively_flattens_an_array() |
||
30 | |||
31 | /** |
||
32 | * @test |
||
33 | */ |
||
34 | View Code Duplication | public function it_recursively_flattens_an_array_to_a_certain_level() |
|
41 | |||
42 | /** |
||
43 | * @test |
||
44 | */ |
||
45 | View Code Duplication | public function it_doesnt_flatten_if_the_amount_of_levels_is_0() |
|
52 | } |
||
53 |
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.