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 | class ComposeManagerStartTest extends PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | public function setUp() |
||
18 | |||
19 | /** |
||
20 | * Test simple start without error |
||
21 | */ |
||
22 | public function testStart() |
||
27 | |||
28 | /** |
||
29 | * Test start success with one compose file |
||
30 | */ |
||
31 | public function testStartWithOneComposeFileSpecified() |
||
36 | |||
37 | /** |
||
38 | * Test start success with two compose files |
||
39 | */ |
||
40 | public function testStartWithTwoComposeFilesSpecified() |
||
45 | |||
46 | /** |
||
47 | * Test start with project option |
||
48 | */ |
||
49 | public function testStartWithprojectOption() |
||
59 | |||
60 | /** |
||
61 | * Test start with ComposeFileNotFoundException |
||
62 | * |
||
63 | * @expectedException \DockerCompose\Exception\ComposeFileNotFoundException |
||
64 | */ |
||
65 | View Code Duplication | public function testStartThrowComposeFileNotFound() |
|
72 | |||
73 | /** |
||
74 | * Test start with DockerHostConnexionErrorException |
||
75 | * |
||
76 | * @expectedException \DockerCompose\Exception\DockerHostConnexionErrorException |
||
77 | */ |
||
78 | View Code Duplication | public function testStartThrowDockerHostConnexionErrorException() |
|
85 | |||
86 | /** |
||
87 | * Test start with DockerInstallationMissingException |
||
88 | * |
||
89 | * @expectedException \DockerCompose\Exception\DockerInstallationMissingException |
||
90 | */ |
||
91 | public function testStartThrowDockerInstallationMissingException() |
||
96 | |||
97 | /** |
||
98 | * Test start with DockerInstallationMissingException |
||
99 | * |
||
100 | * @expectedException \Exception |
||
101 | */ |
||
102 | public function testStartThrowUnknownException() |
||
107 | } |
||
108 |
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.