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 | trait ModuleVerification |
||
10 | { |
||
11 | /** |
||
12 | * Verify whether given modules exist and are active |
||
13 | * |
||
14 | * @param Collection $moduleNames |
||
15 | * |
||
16 | * @return Collection |
||
17 | * @throws Exception |
||
18 | */ |
||
19 | View Code Duplication | protected function verifyActive(Collection $moduleNames) |
|
28 | |||
29 | /** |
||
30 | * Verify whether given modules exist |
||
31 | * |
||
32 | * @param Collection $moduleNames |
||
33 | * |
||
34 | * @return Collection |
||
35 | * @throws Exception |
||
36 | */ |
||
37 | View Code Duplication | protected function verifyExisting(Collection $moduleNames) |
|
46 | |||
47 | /** |
||
48 | * Verifies whether given modules exist and whether they are active |
||
49 | * |
||
50 | * @param Collection $moduleNames |
||
51 | * @param bool $verifyActive |
||
52 | * |
||
53 | * @return Collection|bool |
||
54 | */ |
||
55 | private function verifyModules(Collection $moduleNames, $verifyActive) |
||
80 | } |
||
81 |
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.