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 DisableKeyCommandTest extends TestCase |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var CommandTester |
||
| 17 | */ |
||
| 18 | protected $commandTester; |
||
| 19 | /** |
||
| 20 | * @var ObjectProphecy |
||
| 21 | */ |
||
| 22 | protected $apiKeyService; |
||
| 23 | |||
| 24 | View Code Duplication | public function setUp() |
|
| 32 | |||
| 33 | /** |
||
| 34 | * @test |
||
| 35 | */ |
||
| 36 | public function providedApiKeyIsDisabled() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @test |
||
| 48 | */ |
||
| 49 | View Code Duplication | public function errorIsReturnedIfServiceThrowsException() |
|
| 62 | } |
||
| 63 |
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.