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 |
||
24 | class Express extends Guided implements Setup |
||
25 | { |
||
26 | /** |
||
27 | * Setup hooks by asking some basic questions |
||
28 | * |
||
29 | * @param \SebastianFeldmann\CaptainHook\Config $config |
||
30 | * @throws \Exception |
||
31 | */ |
||
32 | 3 | public function configureHooks(Config $config) |
|
44 | |||
45 | /** |
||
46 | * Setup the commit message hook |
||
47 | * |
||
48 | * @param \SebastianFeldmann\CaptainHook\Config\Hook $config |
||
49 | * @throws \Exception |
||
50 | */ |
||
51 | 3 | private function setupMessageHook(Config\Hook $config) |
|
65 | |||
66 | /** |
||
67 | * Setup the linting hook |
||
68 | * |
||
69 | * @param \SebastianFeldmann\CaptainHook\Config\Hook $config |
||
70 | * @throws \Exception |
||
71 | */ |
||
72 | 3 | View Code Duplication | private function setupPHPLintingHook(Config\Hook $config) |
85 | |||
86 | /** |
||
87 | * Setup the phpunit hook |
||
88 | * |
||
89 | * @param \SebastianFeldmann\CaptainHook\Config\Hook $config |
||
90 | * @throws \Exception |
||
91 | */ |
||
92 | 3 | View Code Duplication | private function setupPHPUnitHook(Config\Hook $config) |
107 | |||
108 | /** |
||
109 | * Setup the code sniffer hook |
||
110 | * |
||
111 | * @param \SebastianFeldmann\CaptainHook\Config\Hook $config |
||
112 | * @throws \Exception |
||
113 | */ |
||
114 | 3 | View Code Duplication | private function setupPHPCodesnifferHook(Config\Hook $config) |
131 | } |
||
132 |
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.