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 Zips |
||
8 | { |
||
9 | /** |
||
10 | * The Http Client. |
||
11 | * |
||
12 | * @var \Mozammil\Putio\Http\Client |
||
13 | */ |
||
14 | protected $client; |
||
15 | |||
16 | public function __construct(Client $client) |
||
20 | |||
21 | /** |
||
22 | * Creates zip file for given files. |
||
23 | * A zip_id is returned to keep track |
||
24 | * of the status of zip creation process. |
||
25 | * |
||
26 | * @param array $file_ids |
||
27 | * |
||
28 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
29 | * |
||
30 | * @see https://api.put.io/v2/docs/zips.html#post--zips-create |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | View Code Duplication | public function create(array $file_ids = []) |
|
42 | |||
43 | /** |
||
44 | * Lists active zip files. |
||
45 | * |
||
46 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
47 | * |
||
48 | * @see https://api.put.io/v2/docs/zips.html#get--zips-list |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | public function list() |
||
56 | |||
57 | /** |
||
58 | * Gives detailed information about the give zip file id. |
||
59 | * Check the zip creation process status with your zip_id. |
||
60 | * When the process is done, you will get url value along |
||
61 | * with size and missing_files. |
||
62 | * You might need to poll this end point |
||
63 | * until you get an url value. |
||
64 | * missing_files is an array of file names |
||
65 | * which are not included into the zip file for some reason. |
||
66 | * |
||
67 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
68 | * |
||
69 | * @see https://api.put.io/v2/docs/zips.html#get-zip |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public function get(int $zip_id) |
||
77 | } |
||
78 |
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.