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 Client extends BaseClient |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * 获取账户报表. |
||
| 11 | * |
||
| 12 | * @param array $params |
||
| 13 | * |
||
| 14 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 15 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 16 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 17 | * |
||
| 18 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 19 | */ |
||
| 20 | public function getAccountReports(array $params) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * 获取推广组报表. |
||
| 27 | * |
||
| 28 | * @param array $params |
||
| 29 | * |
||
| 30 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 31 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 32 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 33 | * |
||
| 34 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 35 | */ |
||
| 36 | public function getAdGroupReports(array $params) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * 获取推广计划报表. |
||
| 43 | * |
||
| 44 | * @param array $params |
||
| 45 | * |
||
| 46 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 47 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 48 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 49 | * |
||
| 50 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 51 | */ |
||
| 52 | public function getCampaignReports(array $params) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * 获取推广创意报表. |
||
| 59 | * |
||
| 60 | * @param array $params |
||
| 61 | * |
||
| 62 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 63 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 64 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 65 | * |
||
| 66 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 67 | */ |
||
| 68 | public function getCreativeReports(array $params) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * 获取app报表. |
||
| 75 | * |
||
| 76 | * @param array $params |
||
| 77 | * |
||
| 78 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 79 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 80 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 81 | * |
||
| 82 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 83 | */ |
||
| 84 | public function getAppReports(array $params) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * 获取受众分析报表. |
||
| 91 | * |
||
| 92 | * @param array $params |
||
| 93 | * |
||
| 94 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 95 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 96 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 97 | * |
||
| 98 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 99 | */ |
||
| 100 | public function getAudienceReports(array $params) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * 获取视频报表. |
||
| 107 | * |
||
| 108 | * @param array $params |
||
| 109 | * |
||
| 110 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 111 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 112 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 113 | * |
||
| 114 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 115 | */ |
||
| 116 | public function getVideoReports(array $params) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * 查询下载任务状态. |
||
| 123 | * |
||
| 124 | * @param number $taskId |
||
| 125 | * @param bool $adReport |
||
| 126 | * |
||
| 127 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 128 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 129 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 130 | * |
||
| 131 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 132 | */ |
||
| 133 | View Code Duplication | public function getFile($taskId, $adReport = true) |
|
| 142 | |||
| 143 | /** |
||
| 144 | * 下载报表文件并转为数组. |
||
| 145 | * |
||
| 146 | * @param number $taskId |
||
| 147 | * @param bool $adReport |
||
| 148 | * |
||
| 149 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\ApiException |
||
| 150 | * @throws \CloudyCity\UCMarketingSDK\Kernel\Exceptions\InvalidArgumentException |
||
| 151 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
| 152 | * |
||
| 153 | * @return array|\Doctrine\Common\Collections\ArrayCollection|object|\Psr\Http\Message\ResponseInterface|string |
||
| 154 | */ |
||
| 155 | View Code Duplication | public function downloadFile($taskId, $adReport = true) |
|
| 164 | } |
||
| 165 |
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.