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 MenuBuilderTest extends \PHPUnit_Framework_TestCase |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var MenuBuilder |
||
| 14 | */ |
||
| 15 | protected $menuBuilder; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @inherit |
||
| 19 | */ |
||
| 20 | protected function setUp() |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @inherit |
||
| 27 | */ |
||
| 28 | protected function tearDown() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
| 35 | */ |
||
| 36 | protected function getEventDispatcher() |
||
| 42 | |||
| 43 | protected function getItem() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
| 52 | */ |
||
| 53 | View Code Duplication | protected function getFactory() |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Test the getters and setters |
||
| 71 | */ |
||
| 72 | public function testGettersAndSetters() |
||
| 90 | |||
| 91 | public function testCreateMainMenu() |
||
| 100 | } |
||
| 101 |
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.