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 |
||
12 | class VMProApiExtensionTest extends \PHPUnit_Framework_TestCase |
||
13 | { |
||
14 | /** |
||
15 | * Get empty configuration set. |
||
16 | * |
||
17 | * @return array |
||
18 | */ |
||
19 | protected function getEmptyConfig() |
||
31 | |||
32 | /** |
||
33 | * Get empty configuration set. |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | protected function getFullConfig() |
||
51 | |||
52 | /** |
||
53 | * Assert whether an exception is thrown when required configuration |
||
54 | * key 'vm_pro_api.credentials' is missing. |
||
55 | * |
||
56 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
57 | */ |
||
58 | View Code Duplication | public function testConfigurationLoadThrowsExceptionUnlessCredentials() |
|
66 | |||
67 | /** |
||
68 | * Assert whether an exception is thrown when required configuration |
||
69 | * key 'vm_pro_api.credentials.username' is missing. |
||
70 | * |
||
71 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
72 | */ |
||
73 | View Code Duplication | public function testConfigurationLoadThrowsExceptionUnlessUsername() |
|
81 | |||
82 | /** |
||
83 | * Assert whether an exception is thrown when required configuration |
||
84 | * key 'vm_pro_api.credentials.password' is missing. |
||
85 | * |
||
86 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
87 | */ |
||
88 | View Code Duplication | public function testConfigurationLoadThrowsExceptionUnlessPassword() |
|
96 | |||
97 | /** |
||
98 | * Assert whether the configuration keys and values are successfully |
||
99 | * written as parameters. |
||
100 | */ |
||
101 | public function testParametersForFullConfig() |
||
114 | |||
115 | /** |
||
116 | * Assert whether the configuration keys and values are successfully |
||
117 | * written as parameters with the right default values. |
||
118 | */ |
||
119 | public function testDefaultParameters() |
||
130 | |||
131 | /** |
||
132 | * Assert whether when Guzzle ^5.0 is installed, the right instance |
||
133 | * of the API client is placed in the dependency injection container. |
||
134 | */ |
||
135 | View Code Duplication | public function testHasGuzzle5Client() |
|
149 | |||
150 | /** |
||
151 | * Assert whether when Guzzle ^6.0 is installed, the right instance |
||
152 | * of the API client is placed in the dependency injection container. |
||
153 | */ |
||
154 | View Code Duplication | public function testHasGuzzle6Client() |
|
168 | } |
||
169 |
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.