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 |
||
| 8 | class ExecResource extends Resource |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Sets up an exec instance in a running container id. |
||
| 12 | * |
||
| 13 | * @param mixed $execConfig Exec configuration |
||
| 14 | * @param array $parameters List of parameters |
||
| 15 | * @param string $fetch Fetch mode (object or response) |
||
| 16 | * |
||
| 17 | * @return \Psr\Http\Message\ResponseInterface |
||
| 18 | */ |
||
| 19 | public function create($execConfig, $parameters = [], $fetch = self::FETCH_OBJECT) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Starts a previously set up exec instance id. If detach is true, this API returns after starting the exec command. Otherwise, this API sets up an interactive session with the exec command. |
||
| 38 | * |
||
| 39 | * @param mixed $execStartConfig Exec configuration |
||
| 40 | * @param mixed $id Exec instance id |
||
| 41 | * @param array $parameters List of parameters |
||
| 42 | * @param string $fetch Fetch mode (object or response) |
||
| 43 | * |
||
| 44 | * @return \Psr\Http\Message\ResponseInterface |
||
| 45 | */ |
||
| 46 | public function start($execStartConfig, $id, $parameters = [], $fetch = self::FETCH_OBJECT) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Resize the tty session used by the exec command id. |
||
| 62 | * |
||
| 63 | * @param mixed $id Exec instance id |
||
| 64 | * @param array $parameters List of parameters |
||
| 65 | * @param string $fetch Fetch mode (object or response) |
||
| 66 | * |
||
| 67 | * @return \Psr\Http\Message\ResponseInterface |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function resize($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
| 83 | |||
| 84 | /** |
||
| 85 | * Return low-level information about the exec command id. |
||
| 86 | * |
||
| 87 | * @param mixed $id Exec instance id |
||
| 88 | * @param array $parameters List of parameters |
||
| 89 | * @param string $fetch Fetch mode (object or response) |
||
| 90 | * |
||
| 91 | * @return \Psr\Http\Message\ResponseInterface |
||
| 92 | */ |
||
| 93 | public function find($id, $parameters = [], $fetch = self::FETCH_OBJECT) |
||
| 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.