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 MemcachedMessagesFrontendCatalogueTest extends WebTestCase |
||
13 | { |
||
14 | /** |
||
15 | * @var \Sleepness\UberTranslationAdminBundle\Frontend\MemcachedMessagesFrontendCatalogue; |
||
16 | */ |
||
17 | private $messagesFrontend; |
||
18 | |||
19 | /** |
||
20 | * @var \Sleepness\UberTranslationBundle\Storage\UberMemcached; |
||
21 | */ |
||
22 | private $uberMemcached; |
||
23 | |||
24 | /** |
||
25 | * Test building catalogue by locale |
||
26 | */ |
||
27 | public function testBuildByLocale() |
||
35 | |||
36 | /** |
||
37 | * Test building catalogue by domain name |
||
38 | */ |
||
39 | View Code Duplication | public function testBuildByDomain() |
|
46 | |||
47 | /** |
||
48 | * Test building catalogue by translation key |
||
49 | */ |
||
50 | View Code Duplication | public function testBuildByKey() |
|
57 | |||
58 | /** |
||
59 | * Test building catalogue by given text |
||
60 | */ |
||
61 | View Code Duplication | public function testBuildByText() |
|
68 | |||
69 | /** |
||
70 | * Test catalogue to get all messages from memcached |
||
71 | */ |
||
72 | public function testGetAll() |
||
78 | |||
79 | /** |
||
80 | * Test replace translation |
||
81 | */ |
||
82 | public function testReplace() |
||
91 | |||
92 | /** |
||
93 | * Set up fixtures for testing |
||
94 | */ |
||
95 | public function setUp() |
||
103 | |||
104 | /** |
||
105 | * Tear down fixtures after testing |
||
106 | */ |
||
107 | public function tearDown() |
||
112 | |||
113 | /** |
||
114 | * Get messages for testing |
||
115 | * |
||
116 | * @return array - messages |
||
117 | */ |
||
118 | private function getMessagesArray() |
||
131 | } |
||
132 |
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.