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 |
||
9 | abstract class WriteFileBase |
||
10 | { |
||
11 | |||
12 | protected $write_destination_folder_path = ""; |
||
13 | protected $dusk_class_and_methods_string = ""; |
||
14 | protected $write_class_name = ""; |
||
15 | protected $spacing = ""; |
||
16 | protected $existing_test_content; |
||
17 | |||
18 | /** |
||
19 | * @var Filesystem |
||
20 | */ |
||
21 | protected $filesystem; |
||
22 | protected $base; |
||
23 | protected $step_template; |
||
24 | protected $content; |
||
25 | |||
26 | /** |
||
27 | * @return string |
||
28 | */ |
||
29 | public function getWriteClassName() |
||
33 | |||
34 | public function setWriteClassName($name) |
||
38 | |||
39 | |||
40 | /** |
||
41 | * @return Filesystem |
||
42 | */ |
||
43 | 48 | public function getFilesystem() |
|
50 | |||
51 | /** |
||
52 | * @param null $filesystem |
||
53 | * @return $this |
||
54 | */ |
||
55 | 48 | public function setFilesystem($filesystem = null) |
|
64 | |||
65 | 24 | protected function convertDuskClassAndMethodsArrayToText($dusk_class_and_methods) |
|
81 | |||
82 | 9 | public function getDuskClassAndMethodsString() |
|
86 | |||
87 | 24 | protected function getAndSetHeaderArea() |
|
92 | |||
93 | abstract protected function getAndSetFooterArea(); |
||
94 | |||
95 | 42 | protected function addSteps(array $steps) |
|
107 | |||
108 | 42 | protected function notLastLine(array $steps, $index) |
|
116 | |||
117 | |||
118 | 42 | protected function addParentContent($parent_function) |
|
124 | |||
125 | 24 | protected function addNewStepToTest($step, $step_template) |
|
135 | |||
136 | 24 | protected function checkDestinationTestFolder() |
|
148 | |||
149 | 42 | protected function saveToFile() |
|
158 | |||
159 | 18 | public function getExistingTestContent() |
|
168 | |||
169 | /** |
||
170 | * @param mixed $existing_test_content |
||
171 | */ |
||
172 | 18 | public function setExistingTestContent($existing_test_content = null) |
|
183 | } |
||
184 |
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.