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 |
||
19 | class UserUpload implements CacheableInterface |
||
20 | { |
||
21 | |||
22 | use CachableTrait; |
||
23 | |||
24 | const BASE_URL = 'http://api.adnxs.com/batch-segment'; |
||
25 | |||
26 | const SANDBOX_BASE_URL = 'http://api-test.adnxs.com/batch-segment'; |
||
27 | |||
28 | /** @var \SplQueue */ |
||
29 | protected $userSegments; |
||
30 | |||
31 | /** @var Client|Auth */ |
||
32 | protected $client; |
||
33 | |||
34 | /** @var int */ |
||
35 | protected $memberId; |
||
36 | |||
37 | /** @var Cache */ |
||
38 | protected $cache; |
||
39 | |||
40 | /** @var string */ |
||
41 | protected $baseUrl; |
||
42 | |||
43 | const CACHE_NAMESPACE = 'appnexus_segment_user_upload'; |
||
44 | |||
45 | const CACHE_EXPIRATION = 3600; |
||
46 | |||
47 | /** |
||
48 | * SegmentRepository constructor. |
||
49 | * |
||
50 | * @param ClientInterface $client |
||
51 | * @param Cache|null $cache |
||
52 | */ |
||
53 | View Code Duplication | public function __construct(ClientInterface $client, Cache $cache = null) |
|
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | public function getBaseUrl() |
||
68 | |||
69 | /** |
||
70 | * @param string $baseUrl |
||
71 | */ |
||
72 | public function setBaseUrl($baseUrl) |
||
76 | |||
77 | |||
78 | /** |
||
79 | * @param $memberId |
||
80 | * @param $fileAsString |
||
81 | * |
||
82 | * @return UploadJobStatus |
||
83 | * @throws UploadException |
||
84 | */ |
||
85 | public function upload($memberId, $fileAsString) |
||
108 | |||
109 | /** |
||
110 | * @param $memberId |
||
111 | * |
||
112 | * @return UploadJobStatus |
||
113 | * @throws UploadException |
||
114 | */ |
||
115 | public function getUploadTicket($memberId) |
||
139 | |||
140 | /** |
||
141 | * @param UploadTicket $uploadTicket |
||
142 | * |
||
143 | * @return UploadJobStatus |
||
144 | * @throws UploadException |
||
145 | */ |
||
146 | public function getJobStatus(UploadTicket $uploadTicket) |
||
170 | |||
171 | /** |
||
172 | * @param $memberId |
||
173 | * @param int $start |
||
174 | * @param int $maxResults |
||
175 | * |
||
176 | * @return UploadJobStatus[] |
||
177 | * @throws \Exception |
||
178 | */ |
||
179 | public function getUploadHistory($memberId, $start = 0, $maxResults = 100) |
||
207 | } |
||
208 |
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.