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 |
||
| 18 | class DoctrineDatabaseTest extends TestCase |
||
| 19 | { |
||
| 20 | const EXISTING_USER_PREFERENCE_ID = 1; |
||
| 21 | const EXISTING_USER_PREFERENCE_DATA = [ |
||
| 22 | 'id' => 1, |
||
| 23 | 'user_id' => 14, |
||
| 24 | 'name' => 'timezone', |
||
| 25 | 'value' => 'America/New_York', |
||
| 26 | ]; |
||
| 27 | |||
| 28 | public function setUp() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @covers \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway::setUserPreference() |
||
| 39 | */ |
||
| 40 | View Code Duplication | public function testInsert() |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @covers \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway::setUserPreference() |
||
| 60 | */ |
||
| 61 | public function testUpdateUserPreference() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @covers \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway::countUserPreferences() |
||
| 81 | */ |
||
| 82 | public function testCountUserPreferences() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @covers \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway::loadUserPreferences() |
||
| 91 | */ |
||
| 92 | public function testLoadUserPreferences() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Return a ready to test DoctrineStorage gateway. |
||
| 118 | * |
||
| 119 | * @return \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway |
||
| 120 | */ |
||
| 121 | protected function getGateway(): Gateway |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param int $id |
||
| 130 | * |
||
| 131 | * @return array |
||
| 132 | */ |
||
| 133 | private function loadUserPreference(int $id): array |
||
| 149 | } |
||
| 150 |