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\User::__construct |
||
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 | |||
130 | /** |
||
131 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::setUserIdentifier |
||
132 | * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getUserIdentifier |
||
133 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
134 | */ |
||
135 | public function testUserIdentifier() |
||
141 | //</editor-fold desc="Public Methods"> |
||
142 | |||
143 | //<editor-fold desc="Private Methods"> |
||
144 | /** |
||
145 | * @return Tournament|MockObject a new tournament |
||
146 | */ |
||
147 | private function tournament(): MockObject |
||
151 | //</editor-fold desc="Private Methods"> |
||
152 | } |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.