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 |
||
27 | class MatchTest extends UnitTestCase |
||
28 | { |
||
29 | //<editor-fold desc="Public Methods"> |
||
30 | /** |
||
31 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getGames |
||
32 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getChildren |
||
33 | * @uses \Tfboe\FmLib\Entity\GameInterface |
||
34 | * @uses \Tfboe\FmLib\Entity\Traits\Match::init |
||
35 | */ |
||
36 | public function testGamesAndChildren() |
||
49 | |||
50 | /** |
||
51 | * @covers \Tfboe\FmLib\Entity\Traits\Match::init |
||
52 | * @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
||
53 | * @uses \Tfboe\FmLib\Entity\Traits\Match::getGames |
||
54 | * @uses \Tfboe\FmLib\Entity\Traits\Match::getRankingsA |
||
55 | * @uses \Tfboe\FmLib\Entity\Traits\Match::getRankingsB |
||
56 | */ |
||
57 | View Code Duplication | public function testInit() |
|
68 | |||
69 | /** |
||
70 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getLevel |
||
71 | */ |
||
72 | public function testLevel() |
||
76 | |||
77 | /** |
||
78 | * @covers \Tfboe\FmLib\Entity\Traits\Match::setMatchNumber |
||
79 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getMatchNumber |
||
80 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getLocalIdentifier |
||
81 | */ |
||
82 | public function testMatchNumberAndLocalIdentifier() |
||
90 | |||
91 | /** |
||
92 | * @covers \Tfboe\FmLib\Entity\Traits\Match::setPhase |
||
93 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getPhase |
||
94 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getParent |
||
95 | * @uses \Tfboe\FmLib\Entity\Traits\Match::getMatchNumber |
||
96 | * @uses \Tfboe\FmLib\Entity\Traits\Match::setMatchNumber |
||
97 | */ |
||
98 | public function testPhaseAndParent() |
||
120 | |||
121 | /** |
||
122 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getRankingsA |
||
123 | * @uses \Tfboe\FmLib\Entity\Ranking |
||
124 | * @uses \Tfboe\FmLib\Entity\Traits\Match::init |
||
125 | */ |
||
126 | View Code Duplication | public function testRankingsA() |
|
136 | |||
137 | /** |
||
138 | * @covers \Tfboe\FmLib\Entity\Traits\Match::getRankingsB |
||
139 | * @uses \Tfboe\FmLib\Entity\Ranking |
||
140 | * @uses \Tfboe\FmLib\Entity\Traits\Match::init |
||
141 | */ |
||
142 | View Code Duplication | public function testRankingsB() |
|
152 | //</editor-fold desc="Public Methods"> |
||
153 | |||
154 | //<editor-fold desc="Private Methods"> |
||
155 | /** |
||
156 | * @return Match|MockObject a new match |
||
157 | */ |
||
158 | private function match(): MockObject |
||
162 | //</editor-fold desc="Private Methods"> |
||
163 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: