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 |
||
14 | final class Exchange implements ExchangeInterface |
||
15 | { |
||
16 | private $connection; |
||
17 | private $channel; |
||
18 | |||
19 | 2 | public function __construct(Connection $connection, Channel $channel) |
|
24 | |||
25 | View Code Duplication | public function declare(Declaration $command): ExchangeInterface |
|
26 | { |
||
27 | $this->connection->send( |
||
28 | $this->connection->protocol()->exchange()->declare( |
||
29 | $this->channel, |
||
30 | $command |
||
31 | ) |
||
32 | ); |
||
33 | |||
34 | if ($command->shouldWait()) { |
||
35 | $this->connection->wait('exchange.declare-ok'); |
||
36 | } |
||
37 | |||
38 | return $this; |
||
39 | } |
||
40 | |||
41 | 1 | View Code Duplication | public function delete(Deletion $command): ExchangeInterface |
56 | } |
||
57 |