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 |
||
14 | class FormatCommandTest extends ContainerTestCase |
||
15 | { |
||
16 | |||
17 | const EXECUTE_OUTPUT_RESULT_OK = '[OK] Done.'; |
||
18 | |||
19 | const EXECUTE_OUTPUT_RESULT_FAIL = '[ERROR] No supported files could be found in the configured directory'; |
||
20 | |||
21 | const EXECUTE_OUTPUT_RESULT_FAIL_TRANS_UNITS = '[ERROR] no-trans-units.de.xlf: No trans-units could be found'; |
||
22 | |||
23 | const EXECUTE_OUTPUT_RESULT_FAIL_DUPLICATE_KEY = '[ERROR] duplicate-keys.de.xlf: Duplicate translation key'; |
||
24 | |||
25 | /** |
||
26 | * Tests the execute method the FormatCommand |
||
27 | */ |
||
28 | View Code Duplication | public function testExecute() |
|
38 | |||
39 | /** |
||
40 | * Tests the execute method the FormatCommand with a non-existing file |
||
41 | */ |
||
42 | View Code Duplication | public function testExecuteWithNonExistingFile() |
|
52 | |||
53 | /** |
||
54 | * Tests the execute method the FormatCommand with a file that should be ignored because of its file-ending |
||
55 | */ |
||
56 | View Code Duplication | public function testExecuteWithIgnoredFile() |
|
66 | |||
67 | /** |
||
68 | * Tests the execute method the FormatCommand with a file that should generate an error because of missing trans-units |
||
69 | */ |
||
70 | View Code Duplication | public function testExecuteWithoutTransUnits() |
|
82 | |||
83 | /** |
||
84 | * Tests the execute method the FormatCommand with a file that should generate an error because of duplicate keys |
||
85 | */ |
||
86 | View Code Duplication | public function testExecuteWithDuplicateKeys() |
|
98 | |||
99 | /** |
||
100 | * Runs the command and returns the result of it along with the output object |
||
101 | * @param array $argv |
||
102 | * @return array |
||
103 | */ |
||
104 | private function runCommand(array $argv = []) |
||
118 | } |
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.