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 |
||
20 | class BridgeMarathon implements BridgeInterface |
||
21 | { |
||
22 | const CACHE_TIME_JOB_LIST = 60; |
||
23 | |||
24 | const CACHE_KEY_APP_LIST = 'marathon.app.list'; |
||
25 | |||
26 | /** |
||
27 | * @var \Chapi\Component\RemoteClients\ApiClientInterface |
||
28 | */ |
||
29 | private $oApiClient; |
||
30 | /** |
||
31 | * @var JobValidatorServiceInterface |
||
32 | */ |
||
33 | private $oJobEntityValidatorService; |
||
34 | /** |
||
35 | * @var CacheInterface |
||
36 | */ |
||
37 | private $oCache; |
||
38 | /** |
||
39 | * @var LoggerInterface |
||
40 | */ |
||
41 | private $oLogger; |
||
42 | |||
43 | private $bCacheHasToDelete = false; |
||
44 | |||
45 | 5 | View Code Duplication | public function __construct( |
58 | |||
59 | 5 | public function __destruct() |
|
66 | |||
67 | /** |
||
68 | * @return JobEntityInterface[] |
||
69 | */ |
||
70 | 1 | public function getJobs() |
|
84 | |||
85 | /** |
||
86 | * @param JobEntityInterface $oJobEntity |
||
87 | * @return bool |
||
88 | */ |
||
89 | 2 | View Code Duplication | public function addJob(JobEntityInterface $oJobEntity) |
98 | |||
99 | /** |
||
100 | * @param JobEntityInterface $oJobEntity |
||
101 | * @return bool |
||
102 | */ |
||
103 | View Code Duplication | public function updateJob(JobEntityInterface $oJobEntity) |
|
112 | |||
113 | /** |
||
114 | * @param JobEntityInterface $oJobEntity |
||
115 | * @return bool |
||
116 | */ |
||
117 | 2 | View Code Duplication | public function removeJob(JobEntityInterface $oJobEntity) |
126 | |||
127 | /** |
||
128 | * @return array|mixed |
||
129 | */ |
||
130 | 1 | private function getJobList() |
|
149 | |||
150 | } |
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.