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 |
||
10 | class RedisMessageProviderTest extends \PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var RedisMessageProvider |
||
14 | */ |
||
15 | private $provider; |
||
16 | |||
17 | private $redis; |
||
18 | private $queueName; |
||
19 | |||
20 | /** |
||
21 | * Set up the test. |
||
22 | */ |
||
23 | public function setUp() |
||
30 | |||
31 | /** |
||
32 | * Test instance |
||
33 | */ |
||
34 | public function testInstance() |
||
38 | |||
39 | /** |
||
40 | * Test get method |
||
41 | */ |
||
42 | public function testGet() |
||
62 | |||
63 | /** |
||
64 | * Test nack with requeue |
||
65 | */ |
||
66 | View Code Duplication | public function testNack() |
|
76 | |||
77 | /** |
||
78 | * Test nack with requeue |
||
79 | */ |
||
80 | View Code Duplication | public function testNackWithNoRequeue() |
|
90 | } |
||
91 |
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.