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 |
||
| 34 | class TournamentTest extends UnitTestCase |
||
| 35 | { |
||
| 36 | //<editor-fold desc="Public Methods"> |
||
| 37 | /** |
||
| 38 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getCompetitions |
||
| 39 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getChildren |
||
| 40 | * @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::getName |
||
| 41 | * @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::setName |
||
| 42 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament::init |
||
| 43 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
| 44 | */ |
||
| 45 | View Code Duplication | public function testCompetitionsAndChildren() |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::init |
||
| 60 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament::getCompetitions |
||
| 61 | * @uses \Tfboe\FmLib\Entity\Traits\Tournament::getTournamentListId |
||
| 62 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
| 63 | */ |
||
| 64 | public function testConstructor() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::setCreator |
||
| 75 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getCreator |
||
| 76 | * @uses \Tfboe\FmLib\Entity\Traits\User::init |
||
| 77 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
| 78 | */ |
||
| 79 | public function testCreator() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getLocalIdentifier |
||
| 89 | * @uses \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getId |
||
| 90 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
| 91 | */ |
||
| 92 | public function testGetLocalIdentifier() |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getLevel |
||
| 102 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
| 103 | */ |
||
| 104 | public function testLevel() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getParent |
||
| 111 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
| 112 | */ |
||
| 113 | public function testParent() |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::setTournamentListId |
||
| 120 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getTournamentListId |
||
| 121 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
| 122 | */ |
||
| 123 | public function testTournamentListId() |
||
| 129 | //</editor-fold desc="Public Methods"> |
||
| 130 | |||
| 131 | //<editor-fold desc="Private Methods"> |
||
| 132 | /** |
||
| 133 | * @return Tournament|MockObject a new tournament |
||
| 134 | */ |
||
| 135 | private function tournament(): MockObject |
||
| 139 | //</editor-fold desc="Private Methods"> |
||
| 140 | } |
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.