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 |
||
17 | class Block extends AbstractApi |
||
18 | { |
||
19 | /** |
||
20 | * Retrieve a list of any active block storage subscriptions on this account. |
||
21 | * |
||
22 | * @return BlockEntity |
||
23 | */ |
||
24 | public function list() |
||
34 | |||
35 | /** |
||
36 | * Retrieve a list of any active block storage subscriptions on this account |
||
37 | * |
||
38 | * @return BlockEntity |
||
39 | * |
||
40 | * @param int $subId Id for the Block storage |
||
41 | */ |
||
42 | public function getById($subId) |
||
48 | |||
49 | /** |
||
50 | * Create a block storage subscription. |
||
51 | * |
||
52 | * @param int $dc_id DCID of the location to create this subscription in |
||
53 | * @param int $size size (in GB) of this subscription |
||
54 | * @param string $label Text label that will be associated with the subscription |
||
55 | **/ |
||
56 | public function create($dc_id, int $size, $label = '') |
||
69 | |||
70 | /** |
||
71 | * Delete a block storage subscription. All data will be permanently lost. |
||
72 | * |
||
73 | * There is no going back from this call. |
||
74 | * |
||
75 | * @param int $subid ID of the block storage subscription to delete |
||
76 | * |
||
77 | * @throws HttpException |
||
78 | */ |
||
79 | public function delete($subid) |
||
83 | |||
84 | /** |
||
85 | * Detach a block storage subscription from the currently attached instance. |
||
86 | * |
||
87 | * @param int $subid ID of the block storage subscription to detach |
||
88 | * |
||
89 | * @throws HttpException |
||
90 | */ |
||
91 | public function detach($subid) |
||
95 | |||
96 | /** |
||
97 | * Set the label of a block storage subscription. |
||
98 | * |
||
99 | * @param int $subid ID of the block storage subscription to detach |
||
100 | * @param string $label Text label that will be shown in the control panel |
||
101 | * |
||
102 | * @throws HttpException |
||
103 | */ |
||
104 | View Code Duplication | public function labelSet($subid, $label) |
|
112 | |||
113 | /** |
||
114 | * Resize the block storage volume to a new size. |
||
115 | * |
||
116 | * WARNING: When shrinking the volume, |
||
117 | * you must manually shrink the filesystem and partitions beforehand, |
||
118 | * or you will lose data. |
||
119 | * |
||
120 | * @param int $subid ID of the block storage subscription to resize |
||
121 | * @param string $size New size (in GB) of the block storage subscription |
||
122 | * |
||
123 | * @throws HttpException |
||
124 | */ |
||
125 | View Code Duplication | public function resize($subid, $size) |
|
133 | } |
||
134 |