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 |
||
13 | class TranslationControllerTest extends WebTestCase |
||
14 | { |
||
15 | /** |
||
16 | * @var \Sleepness\UberTranslationBundle\Storage\UberMemcached; |
||
17 | */ |
||
18 | private $uberMemcached; |
||
19 | |||
20 | private $client; |
||
21 | |||
22 | /** |
||
23 | * Test indexAction() of TranslationController |
||
24 | */ |
||
25 | public function testIndexAction() |
||
31 | |||
32 | /** |
||
33 | * Test editAction() of TranslationController |
||
34 | */ |
||
35 | View Code Duplication | public function testEditAction() |
|
42 | |||
43 | /** |
||
44 | * Test deleteAction() of TranslationController |
||
45 | */ |
||
46 | public function testDeleteAction() |
||
51 | |||
52 | /** |
||
53 | * Test createAction() of TranslationController |
||
54 | */ |
||
55 | View Code Duplication | public function testCreateAction() |
|
62 | |||
63 | /** |
||
64 | * Test checkAction() of TranslationController |
||
65 | */ |
||
66 | public function testCheckAction() |
||
81 | |||
82 | /** |
||
83 | * Common asserts for response |
||
84 | * |
||
85 | * @param $response |
||
86 | */ |
||
87 | private function responseAsserts($response) |
||
98 | |||
99 | /** |
||
100 | * Set up fixtures for testing |
||
101 | */ |
||
102 | public function setUp() |
||
110 | |||
111 | /** |
||
112 | * Tear down fixtures after testing |
||
113 | */ |
||
114 | public function tearDown() |
||
118 | } |
||
119 |
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.