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 |
||
24 | View Code Duplication | final class Key implements Api |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Create a new keypair. |
||
28 | * |
||
29 | * @Endpoint(name="key:gen") |
||
30 | * |
||
31 | * @param string $arg name of key to create Required: |
||
32 | * @param string $type type of the key to create |
||
33 | * @param int $size size of the key to generate |
||
34 | * |
||
35 | * @return Command |
||
36 | */ |
||
37 | public function gen(string $arg, string $type = null, int $size = 0): Command |
||
41 | |||
42 | /** |
||
43 | * List all local keypairs. |
||
44 | * |
||
45 | * @Endpoint(name="key:list") |
||
46 | * |
||
47 | * @param bool $l show extra information about keys |
||
48 | * |
||
49 | * @return Command |
||
50 | */ |
||
51 | public function list(bool $l = null): Command |
||
55 | } |
||
56 |
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.