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 |
||
| 7 | class WorkflowHandler |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var mixed |
||
| 11 | */ |
||
| 12 | private $config; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var mixed |
||
| 16 | */ |
||
| 17 | private $harvest; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var mixed |
||
| 21 | */ |
||
| 22 | private $toggl; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param Config $config |
||
| 26 | */ |
||
| 27 | View Code Duplication | public function __construct(Config $config = null) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @param $projectId |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function getProjectName($projectId) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | public function getProjects() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return mixed |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function getRecentTimers() |
|
| 80 | |||
| 81 | /** |
||
| 82 | * @param $service |
||
| 83 | * @return mixed |
||
| 84 | */ |
||
| 85 | public function getServiceDataCache($service) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @return mixed |
||
| 98 | */ |
||
| 99 | public function getTags() |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param $service |
||
| 106 | * @param null $action |
||
| 107 | * @param null $success |
||
| 108 | */ |
||
| 109 | public function getNotification(array $results = [], $action = null) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param $service |
||
| 126 | * @param null $action |
||
| 127 | * @param null $success |
||
| 128 | */ |
||
| 129 | public function getNotificationForService($service = null, $action = null, $success = null) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @return mixed |
||
| 142 | */ |
||
| 143 | View Code Duplication | public function syncOnlineDataToLocalCache() |
|
| 155 | |||
| 156 | /** |
||
| 157 | * @param $needle |
||
| 158 | * @return mixed |
||
| 159 | */ |
||
| 160 | private function getItems($needle) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @return mixed |
||
| 185 | */ |
||
| 186 | private function getRecentServiceTimers($service) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param $data |
||
| 193 | * @param string $service |
||
| 194 | */ |
||
| 195 | private function saveServiceDataCache($service, $data) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @param $service |
||
| 203 | * @return mixed |
||
| 204 | */ |
||
| 205 | private function syncServiceOnlineDataToLocalCache($service) |
||
| 217 | } |
||
| 218 |
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.