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 WorkflowProfileRepositoryTest extends AbstractKernelTestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var WorkflowProfileRepositoryInterface |
||
18 | */ |
||
19 | protected $repository; |
||
20 | |||
21 | protected $statusRepository; |
||
22 | |||
23 | /** |
||
24 | * Set up test |
||
25 | */ |
||
26 | View Code Duplication | protected function setUp() |
|
34 | |||
35 | /** |
||
36 | * Test hasTransition |
||
37 | * |
||
38 | * @param string $fromStatusName |
||
39 | * @param string $toStatusName |
||
40 | * @param boolean $expectedBool |
||
41 | * |
||
42 | * @dataProvider provideTransitions |
||
43 | */ |
||
44 | public function testHasTransition($fromStatusName, $toStatusName, $expectedBool) |
||
51 | |||
52 | /** |
||
53 | * Provide transition status |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | public function provideTransitions() |
||
64 | |||
65 | /** |
||
66 | * @param PaginateFinderConfiguration $configuration |
||
67 | * @param int $count |
||
68 | * |
||
69 | * @dataProvider providePaginateAndSearch |
||
70 | */ |
||
71 | public function testFindForPaginate(PaginateFinderConfiguration $configuration, $count) |
||
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | View Code Duplication | public function providePaginateAndSearch() |
|
94 | |||
95 | /** |
||
96 | * test count all workflow profile |
||
97 | */ |
||
98 | public function testCount() |
||
103 | |||
104 | /** |
||
105 | * @param PaginateFinderConfiguration $configuration |
||
106 | * @param int $count |
||
107 | * |
||
108 | * @dataProvider provideCountWithFilter |
||
109 | */ |
||
110 | public function testCountWithFilter($configuration, $count) |
||
115 | |||
116 | /** |
||
117 | * @return array |
||
118 | */ |
||
119 | View Code Duplication | public function provideCountWithFilter() |
|
133 | |||
134 | /** |
||
135 | * Test remove workflow profile |
||
136 | */ |
||
137 | public function testRemoveWorkflowProfile() |
||
153 | } |
||
154 |
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.