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 |
||
35 | class Playbacks extends AriClientAware |
||
36 | { |
||
37 | const OPERATION_PAUSE = 'pause'; |
||
38 | const OPERATION_UNPAUSE = 'unpause'; |
||
39 | const OPERATION_REVERSE = 'reverse'; |
||
40 | const OPERATION_FORWARD = 'forward'; |
||
41 | const OPERATION_RESTART = 'restart'; |
||
42 | |||
43 | /** |
||
44 | * Get a playback's details. |
||
45 | * |
||
46 | * @param string $playbackId Playback's id |
||
47 | * @return Playback |
||
48 | * @throws NotFoundException |
||
49 | */ |
||
50 | public function getPlayback($playbackId) |
||
61 | |||
62 | /** |
||
63 | * Stop a playback. |
||
64 | * |
||
65 | * @param string $playbackId Playback's id |
||
66 | * @throws NotFoundException |
||
67 | */ |
||
68 | View Code Duplication | public function stopPlayback($playbackId) |
|
77 | |||
78 | /** |
||
79 | * Control a playback. |
||
80 | * |
||
81 | * @param string $playbackId Playback's id |
||
82 | * @param string $operation (required) Operation to perform on the playback. Allowed values: restart, pause, unpause, reverse, forward. |
||
83 | * @throws ConflictException |
||
84 | * @throws InvalidParameterException |
||
85 | * @throws NotFoundException |
||
86 | */ |
||
87 | View Code Duplication | public function controlPlayback($playbackId, $operation) |
|
102 | |||
103 | } |
||
104 |
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.