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 |
||
27 | class FirehoseAdapterTest extends TestCase |
||
28 | { |
||
29 | /** @var MessageInterface|MockInterface */ |
||
30 | private $messageA; |
||
31 | /** @var MessageInterface|MockInterface */ |
||
32 | private $messageB; |
||
33 | /** @var MessageInterface|MockInterface */ |
||
34 | private $messageC; |
||
35 | /** @var MessageInterface[]|MockInterface[] */ |
||
36 | private $messages; |
||
37 | /** @var ResultInterface|MockInterface */ |
||
38 | private $model; |
||
39 | /** @var MessageFactoryInterface|MockInterface */ |
||
40 | private $factory; |
||
41 | /** @var FirehoseClient */ |
||
42 | private $client; |
||
43 | |||
44 | View Code Duplication | public function setUp() |
|
55 | |||
56 | public function testInterface() |
||
60 | |||
61 | public function testEnqueue() |
||
82 | |||
83 | /** |
||
84 | * @expectedException \Graze\Queue\Adapter\Exception\MethodNotSupportedException |
||
85 | */ |
||
86 | public function testAcknowledge() |
||
91 | |||
92 | /** |
||
93 | * @expectedException \Graze\Queue\Adapter\Exception\MethodNotSupportedException |
||
94 | */ |
||
95 | public function testDequeue() |
||
100 | |||
101 | /** |
||
102 | * @expectedException \Graze\Queue\Adapter\Exception\MethodNotSupportedException |
||
103 | */ |
||
104 | public function testPurge() |
||
109 | |||
110 | /** |
||
111 | * @expectedException \Graze\Queue\Adapter\Exception\MethodNotSupportedException |
||
112 | */ |
||
113 | public function testDelete() |
||
118 | } |
||
119 |
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.