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 |
||
10 | final class DataContainerTest extends \PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | /** |
||
13 | * Verifies basic behaviour of the DataContainer class |
||
14 | * |
||
15 | * @test |
||
16 | * @covers ::getOffset |
||
17 | * @covers ::getLimit |
||
18 | * @covers ::getTotal |
||
19 | * @covers ::getCount |
||
20 | * @covers ::getResults |
||
21 | * |
||
22 | * @return void |
||
23 | */ |
||
24 | public function basicUsage() |
||
44 | |||
45 | /** |
||
46 | * Verifies behaviour of __construct when $input is empty. |
||
47 | * |
||
48 | * @test |
||
49 | * |
||
50 | * @return void |
||
51 | */ |
||
52 | public function constructDefaults() |
||
61 | |||
62 | /** |
||
63 | * Verifies behaviour of __construct when $input['results']['resourceURI'] is null. |
||
64 | * |
||
65 | * @test |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | View Code Duplication | public function constructNullResourceURI() |
|
82 | |||
83 | /** |
||
84 | * Verifies behaviour of __construct when $input['results']['resourceURI'] does not match the regex pattern. |
||
85 | * |
||
86 | * @test |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | View Code Duplication | public function constructInvalidResourceURI() |
|
103 | } |
||
104 |
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.