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 |
||
13 | class PublisherTest extends BaseTestCase |
||
14 | { |
||
15 | public function testGetQueueName() |
||
16 | { |
||
17 | $publisher = new Publisher( |
||
18 | 'exch_test', |
||
19 | ExchangeType::FANOUT, |
||
20 | $this->getConnectionManagerMock(), |
||
21 | 'from_name_test', |
||
22 | 'test' |
||
23 | ); |
||
24 | |||
25 | $this->assertEquals('test', $publisher->getQueueName()); |
||
26 | } |
||
27 | |||
28 | public function testGetExchange() |
||
39 | |||
40 | View Code Duplication | public function testGetExchangeType() |
|
51 | |||
52 | View Code Duplication | public function testGetFromName() |
|
64 | |||
65 | /** |
||
66 | * @return ConnectionManager |
||
67 | */ |
||
68 | View Code Duplication | protected function getConnectionManagerMock() |
|
78 | |||
79 | /** |
||
80 | * @return CmobiAMQPConnection |
||
81 | */ |
||
82 | View Code Duplication | protected function getConnectionMock() |
|
96 | |||
97 | /** |
||
98 | * @return CmobiAMQPChannel |
||
99 | */ |
||
100 | View Code Duplication | protected function getChannelMock() |
|
115 | |||
116 | /** |
||
117 | * @param string $msg |
||
118 | * @param null $correlationId |
||
119 | * |
||
120 | * @return CmobiAMQPMessage |
||
121 | */ |
||
122 | View Code Duplication | protected function getCmobiAMQPMessage($msg = '', $correlationId = null) |
|
135 | } |
||
136 |
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.