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 ConfigurationTest extends AbstractExtensionConfigurationTestCase |
||
13 | { |
||
14 | private $emptyConfig = [ |
||
15 | 'main_alias' => [ |
||
16 | 'client' => 'httplug.client.default', |
||
17 | 'message_factory' => 'httplug.message_factory.default', |
||
18 | 'uri_factory' => 'httplug.uri_factory.default', |
||
19 | 'stream_factory' => 'httplug.stream_factory.default', |
||
20 | ], |
||
21 | 'classes' => [ |
||
22 | 'client' => null, |
||
23 | 'message_factory' => null, |
||
24 | 'uri_factory' => null, |
||
25 | 'stream_factory' => null, |
||
26 | ], |
||
27 | 'clients' => [], |
||
28 | 'profiling' => [ |
||
29 | 'enabled' => true, |
||
30 | 'formatter' => null, |
||
31 | 'captured_body_length' => 0, |
||
32 | ], |
||
33 | 'plugins' => [ |
||
34 | 'authentication' => [], |
||
35 | 'cache' => [ |
||
36 | 'enabled' => false, |
||
37 | 'stream_factory' => 'httplug.stream_factory', |
||
38 | 'config' => [ |
||
39 | 'methods' => ['GET', 'HEAD'], |
||
40 | ], |
||
41 | ], |
||
42 | 'cookie' => [ |
||
43 | 'enabled' => false, |
||
44 | ], |
||
45 | 'decoder' => [ |
||
46 | 'enabled' => true, |
||
47 | 'use_content_encoding' => true, |
||
48 | ], |
||
49 | 'history' => [ |
||
50 | 'enabled' => false, |
||
51 | ], |
||
52 | 'logger' => [ |
||
53 | 'enabled' => true, |
||
54 | 'logger' => 'logger', |
||
55 | 'formatter' => null, |
||
56 | ], |
||
57 | 'redirect' => [ |
||
58 | 'enabled' => true, |
||
59 | 'preserve_header' => true, |
||
60 | 'use_default_for_multiple' => true, |
||
61 | ], |
||
62 | 'retry' => [ |
||
63 | 'enabled' => true, |
||
64 | 'retry' => 1, |
||
65 | ], |
||
66 | 'stopwatch' => [ |
||
67 | 'enabled' => true, |
||
68 | 'stopwatch' => 'debug.stopwatch', |
||
69 | ], |
||
70 | ], |
||
71 | 'discovery' => [ |
||
72 | 'client' => 'auto', |
||
73 | 'async_client' => null, |
||
74 | ], |
||
75 | ]; |
||
76 | |||
77 | protected function getContainerExtension() |
||
81 | |||
82 | protected function getConfiguration() |
||
86 | |||
87 | View Code Duplication | public function testEmptyConfiguration() |
|
101 | |||
102 | public function testSupportsAllConfigFormats() |
||
274 | |||
275 | /** |
||
276 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
277 | * @expectedExceptionMessage Nonexisting\Class |
||
278 | */ |
||
279 | public function testMissingClass() |
||
284 | |||
285 | /** |
||
286 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
287 | * @expectedExceptionMessage Unrecognized option "foobar" under "httplug.clients.acme.plugins.0" |
||
288 | */ |
||
289 | public function testInvalidPlugin() |
||
294 | |||
295 | /** |
||
296 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
297 | * @expectedExceptionMessage password, service, username |
||
298 | */ |
||
299 | public function testInvalidAuthentication() |
||
304 | |||
305 | /** |
||
306 | * @group legacy |
||
307 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
308 | * @expectedExceptionMessage Invalid configuration for path "httplug.plugins.cache.config": You can't provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaniously. Use "respect_response_cache_directives" instead. |
||
309 | */ |
||
310 | public function testInvalidCacheConfig() |
||
315 | |||
316 | /** |
||
317 | * @group legacy |
||
318 | */ |
||
319 | View Code Duplication | public function testBackwardCompatibility() |
|
332 | |||
333 | /** |
||
334 | * @group legacy |
||
335 | */ |
||
336 | View Code Duplication | public function testCacheConfigDeprecationCompatibility() |
|
350 | |||
351 | /** |
||
352 | * @group legacy |
||
353 | */ |
||
354 | View Code Duplication | public function testCacheConfigDeprecationCompatibilityIssue166() |
|
368 | |||
369 | /** |
||
370 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
371 | * @expectedExceptionMessage Can't configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling". |
||
372 | */ |
||
373 | public function testProfilingToolbarCollision() |
||
378 | |||
379 | /** |
||
380 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
381 | * @expectedExceptionMessage The child node "cache_pool" at path "httplug.clients.test.plugins.0.cache" must be configured. |
||
382 | */ |
||
383 | public function testClientCacheConfigMustHavePool() |
||
388 | |||
389 | /** |
||
390 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
391 | * @expectedExceptionMessage The child node "cache_pool" at path "httplug.plugins.cache" must be configured. |
||
392 | */ |
||
393 | public function testCacheConfigMustHavePool() |
||
398 | |||
399 | public function testLimitlessCapturedBodyLength() |
||
406 | |||
407 | /** |
||
408 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
409 | * @expectedExceptionMessage The child node "captured_body_length" at path "httplug.profiling" must be an integer or null. |
||
410 | */ |
||
411 | public function testInvalidCapturedBodyLengthString() |
||
416 | } |
||
417 |
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.