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 |
||
8 | class EnvironmentOverview extends Dispatcher { |
||
9 | |||
10 | const ACTION_OVERVIEW = 'overview'; |
||
11 | |||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private static $action_types = [ |
||
16 | self::ACTION_OVERVIEW |
||
17 | ]; |
||
18 | |||
19 | View Code Duplication | public function init() { |
|
28 | |||
29 | /** |
||
30 | * |
||
31 | * @param \SS_HTTPRequest $request |
||
32 | * |
||
33 | * @return \HTMLText|\SS_HTTPResponse |
||
34 | */ |
||
35 | public function index(\SS_HTTPRequest $request) { |
||
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | public function Link() { |
||
53 | |||
54 | /** |
||
55 | * The model includes the CSRF tokens and the various API |
||
56 | * endpoints that the front end might be interested in. |
||
57 | * |
||
58 | * @param string $name |
||
59 | * |
||
60 | * @return array |
||
61 | */ |
||
62 | public function getModel($name = '') { |
||
76 | |||
77 | } |
||
78 |
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.