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 |
||
15 | class AuctionApi |
||
16 | { |
||
17 | /** |
||
18 | * @var AuthenticationModel |
||
19 | */ |
||
20 | private $authenticationModel; |
||
21 | |||
22 | /** |
||
23 | * @var RequestService |
||
24 | */ |
||
25 | private $requestService; |
||
26 | |||
27 | /** |
||
28 | * AuctionApi constructor. |
||
29 | * |
||
30 | * @param AuthenticationModel $authenticationModel |
||
31 | * @param RequestService $requestService |
||
32 | */ |
||
33 | public function __construct( |
||
40 | |||
41 | /** |
||
42 | * This API resource provides a per-realm list of recently generated auction house data dumps |
||
43 | * |
||
44 | * Since the returned JSON string is to huge to decode with native functions I decided to only |
||
45 | * return the url for retrieving the JSON string |
||
46 | * |
||
47 | * @param int $realm |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | public function getAuctionDataStatus($realm) |
||
58 | |||
59 | /** |
||
60 | * @param string $field |
||
61 | * |
||
62 | * @return RequestModel |
||
63 | */ |
||
64 | View Code Duplication | private function prepareRequestModel($field) |
|
76 | |||
77 | /** |
||
78 | * @param string $field |
||
79 | * |
||
80 | * @return \StdClass |
||
81 | */ |
||
82 | View Code Duplication | private function prepareResponseObject($field) |
|
90 | } |
||
91 |
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.