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 |
||
15 | class SshTransport implements TransportInterface |
||
16 | { |
||
17 | protected $tty; |
||
18 | protected $siteAlias; |
||
19 | |||
20 | public function __construct(SiteAliasInterface $siteAlias) |
||
24 | |||
25 | /** |
||
26 | * @inheritdoc |
||
27 | */ |
||
28 | public function configure(SiteProcess $process) |
||
32 | |||
33 | /** |
||
34 | * inheritdoc |
||
35 | */ |
||
36 | View Code Duplication | public function wrap($args) |
|
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | public function addChdir($cd_remote, $args) |
||
63 | |||
64 | /** |
||
65 | * getTransportOptions returns the transport options for the tranport |
||
66 | * mechanism itself |
||
67 | */ |
||
68 | protected function getTransportOptions() |
||
79 | |||
80 | /** |
||
81 | * getCommandToExecute processes the arguments for the command to |
||
82 | * be executed such that they are appropriate for the transport mechanism. |
||
83 | */ |
||
84 | View Code Duplication | protected function getCommandToExecute($args) |
|
92 | } |
||
93 |
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.