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 |
||
33 | class DeviceStates extends AriClientAware |
||
34 | { |
||
35 | |||
36 | /** |
||
37 | * List all ARI controlled device states. |
||
38 | * |
||
39 | * @return DeviceState[] |
||
40 | */ |
||
41 | 1 | public function getDeviceStates() |
|
53 | |||
54 | /** |
||
55 | * Retrieve the current state of a device. |
||
56 | * |
||
57 | * @param string $deviceName |
||
58 | * @return DeviceState |
||
59 | */ |
||
60 | 3 | public function getDeviceState($deviceName) |
|
67 | |||
68 | /** |
||
69 | * Change the state of a device controlled by ARI. (Note - implicitly creates the device state). |
||
70 | * |
||
71 | * @param string $deviceName Name of the device |
||
72 | * @param string $deviceState (required) Device state value |
||
73 | * @throws ConflictException |
||
74 | * @throws NotFoundException |
||
75 | */ |
||
76 | 2 | public function updateDeviceState($deviceName, $deviceState) |
|
89 | |||
90 | /** |
||
91 | * Destroy a device-state controlled by ARI. |
||
92 | * |
||
93 | * @param string $deviceName Name of the device |
||
94 | * @throws ConflictException |
||
95 | * @throws NotFoundException |
||
96 | */ |
||
97 | 2 | View Code Duplication | public function deleteDeviceState($deviceName) |
108 | |||
109 | } |
||
110 |
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.