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 |
||
12 | class TaskTest extends BaseTestCase |
||
13 | { |
||
14 | public function testGetQueueName() |
||
20 | |||
21 | public function testRefreshChannel() |
||
27 | |||
28 | public function testGetChannel() |
||
34 | |||
35 | public function testGetFromName() |
||
41 | |||
42 | /** |
||
43 | * @return ConnectionManager |
||
44 | */ |
||
45 | View Code Duplication | protected function getConnectionManagerMock() |
|
55 | |||
56 | /** |
||
57 | * @return CmobiAMQPConnection |
||
58 | */ |
||
59 | View Code Duplication | protected function getConnectionMock() |
|
73 | |||
74 | /** |
||
75 | * @return CmobiAMQPChannel |
||
76 | */ |
||
77 | View Code Duplication | protected function getChannelMock() |
|
78 | { |
||
79 | $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class) |
||
80 | ->disableOriginalConstructor() |
||
81 | ->getMock(); |
||
82 | $channelMock |
||
83 | ->expects($this->any()) |
||
84 | ->method('basic_publish') |
||
85 | ->willReturn(true); |
||
86 | $channelMock |
||
87 | ->method('basicConsume') |
||
88 | ->willReturn(true); |
||
89 | |||
90 | return $channelMock; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param string $msg |
||
95 | * @param null $correlationId |
||
96 | * |
||
97 | * @return CmobiAMQPMessage |
||
98 | */ |
||
99 | View Code Duplication | protected function getCmobiAMQPMessage($msg = '', $correlationId = null) |
|
112 | } |
||
113 |
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.