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 KeywordRepositoryTest extends AbstractKernelTestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var KeywordRepositoryInterface |
||
18 | */ |
||
19 | protected $repository; |
||
20 | |||
21 | /** |
||
22 | * Set up test |
||
23 | */ |
||
24 | protected function setUp() |
||
31 | |||
32 | /** |
||
33 | * @param PaginateFinderConfiguration $configuration |
||
34 | * @param int $count |
||
35 | * |
||
36 | * @dataProvider providePaginateAndSearch |
||
37 | */ |
||
38 | public function testFindForPaginate(PaginateFinderConfiguration $configuration, $count) |
||
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | */ |
||
47 | public function providePaginateAndSearch() |
||
61 | |||
62 | /** |
||
63 | * test count all keyword |
||
64 | */ |
||
65 | public function testCount() |
||
70 | |||
71 | /** |
||
72 | * @param PaginateFinderConfiguration $configuration |
||
73 | * @param int $count |
||
74 | * |
||
75 | * @dataProvider provideCountWithFilter |
||
76 | */ |
||
77 | public function testCountWithFilter($configuration, $count) |
||
82 | |||
83 | /** |
||
84 | * @return array |
||
85 | */ |
||
86 | public function provideCountWithFilter() |
||
98 | |||
99 | /** |
||
100 | * Test remove keywords |
||
101 | */ |
||
102 | View Code Duplication | public function testRemoveKeywords() |
|
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.