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 |
||
29 | class ConnectionFactoryTest extends AbstractTestCase |
||
30 | { |
||
31 | View Code Duplication | public function testMake() |
|
|
|||
32 | { |
||
33 | $factory = $this->getMockedFactory(); |
||
34 | |||
35 | $return = $factory->make(['driver' => 'guzzlehttp', 'username' => 'your-username', 'password' => 'your-password', 'accept' => 'application/json']); |
||
36 | |||
37 | $this->assertInstanceOf(AdapterInterface::class, $return); |
||
38 | } |
||
39 | |||
40 | public function createDataProvider() |
||
48 | |||
49 | /** |
||
50 | * @dataProvider createDataProvider |
||
51 | */ |
||
52 | public function testCreateWorkingDriver($driver, $class) |
||
60 | |||
61 | /** |
||
62 | * @expectedException \InvalidArgumentException |
||
63 | * @expectedExceptionMessage A driver must be specified. |
||
64 | */ |
||
65 | public function testCreateEmptyDriverConnector() |
||
71 | |||
72 | /** |
||
73 | * @expectedException \InvalidArgumentException |
||
74 | * @expectedExceptionMessage Unsupported driver [unsupported]. |
||
75 | */ |
||
76 | public function testCreateUnsupportedDriverConnector() |
||
82 | |||
83 | protected function getConnectionFactory() |
||
87 | |||
88 | protected function getMockedFactory() |
||
104 | } |
||
105 |
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.