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 namespace Comodojo\RpcClient\Components; |
||
24 | trait Request { |
||
25 | |||
26 | /** |
||
27 | * Autoclean requests |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $autoclean = true; |
||
32 | |||
33 | private $requests = array(); |
||
34 | |||
35 | /** |
||
36 | * Set autoclean on/off |
||
37 | * |
||
38 | * @param bool $mode If true, requests will be removed from queue at each send() |
||
39 | * |
||
40 | * @return \Comodojo\RpcClient\RpcClient |
||
41 | */ |
||
42 | public function setAutoclean($mode = true) { |
||
49 | |||
50 | public function getAutoclean() { |
||
55 | |||
56 | public function clean() { |
||
63 | |||
64 | public function addRequest(RpcRequest $request) { |
||
73 | |||
74 | public function getRequest($uid = null) { |
||
91 | |||
92 | public function deleteRequest($uid = null) { |
||
113 | |||
114 | } |
||
115 |
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.