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 |
||
21 | class EntityComparerByTimeStartTimeAndLocalIdentifierTest extends UnitTestCase |
||
22 | { |
||
23 | //<editor-fold desc="Public Methods"> |
||
24 | /** |
||
25 | * @return array |
||
26 | */ |
||
27 | public function localIdentifierProvider() |
||
31 | |||
32 | /** |
||
33 | * @return array |
||
34 | */ |
||
35 | public function localIdentifierProviderWithoutZero() |
||
42 | |||
43 | /** |
||
44 | * @dataProvider timePairProvider |
||
45 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::compareEntities |
||
46 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
47 | * ::compareEntityTimes |
||
48 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::__construct |
||
49 | * @uses \Tfboe\FmLib\Service\RankingSystem\RecursiveEndStartTimeService::getTime |
||
50 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
51 | * ::compareLocalIdentifiersWithinTournament |
||
52 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::getPredecessors |
||
53 | * @param \DateTime $time1 |
||
54 | * @param \DateTime $time2 |
||
55 | * @param int $expectedResult |
||
56 | */ |
||
57 | public function testCompareEntitiesDifferentEntityTimesGrandparentLevel(\DateTime $time1, \DateTime $time2, |
||
74 | |||
75 | /** |
||
76 | * @dataProvider timePairProvider |
||
77 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::compareEntities |
||
78 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
79 | * ::compareEntityTimes |
||
80 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::__construct |
||
81 | * @uses \Tfboe\FmLib\Service\RankingSystem\RecursiveEndStartTimeService::getTime |
||
82 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
83 | * ::compareLocalIdentifiersWithinTournament |
||
84 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::getPredecessors |
||
85 | * @param \DateTime $time1 |
||
86 | * @param \DateTime $time2 |
||
87 | * @param int $expectedResult |
||
88 | */ |
||
89 | public function testCompareEntitiesDifferentEntityTimesOneLevel(\DateTime $time1, \DateTime $time2, |
||
101 | |||
102 | /** |
||
103 | * @dataProvider localIdentifierProvider |
||
104 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::compareEntities |
||
105 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::__construct |
||
106 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
107 | * ::compareEntityTimes |
||
108 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
109 | * ::compareLocalIdentifiersWithinTournament |
||
110 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::getPredecessors |
||
111 | * @uses \Tfboe\FmLib\Service\RankingSystem\RecursiveEndStartTimeService::getTime |
||
112 | * @param mixed $localIdentifier1 the local identifier of entity1 |
||
113 | * @param mixed $localIdentifier2 the local identifier of entity2 |
||
114 | * @param int $expectedResult |
||
115 | */ |
||
116 | public function testCompareEntitiesSameEntityTimesDifferentLocalIdentifiers($localIdentifier1, $localIdentifier2, |
||
131 | |||
132 | /** @noinspection PhpDocMissingThrowsInspection */ //ReflectionException |
||
133 | /** |
||
134 | * @dataProvider timePairProvider |
||
135 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
136 | * ::compareEntityTimes |
||
137 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::__construct |
||
138 | * @uses \Tfboe\FmLib\Service\RankingSystem\RecursiveEndStartTimeService::getTime |
||
139 | * @param \DateTime $time1 the start time of the first entity |
||
140 | * @param \DateTime $time2 the start time of the second entity |
||
141 | * @param int $expectedResult the expected result of the method |
||
142 | */ |
||
143 | public function testCompareEntityTimesWithStartTimes(\DateTime $time1, \DateTime $time2, int $expectedResult) |
||
154 | |||
155 | /** @noinspection PhpDocMissingThrowsInspection */ //ReflectionException |
||
156 | /** |
||
157 | * @dataProvider timePairProvider |
||
158 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
159 | * ::compareEntityTimes |
||
160 | * @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::__construct |
||
161 | * @uses \Tfboe\FmLib\Service\RankingSystem\RecursiveEndStartTimeService::getTime |
||
162 | * @param \DateTime $time1 the end time of the first entity |
||
163 | * @param \DateTime $time2 the end time of the second entity |
||
164 | * @param int $expectedResult the expected result of the method |
||
165 | */ |
||
166 | View Code Duplication | public function testCompareEntityTimesWithoutStartTimes(\DateTime $time1, \DateTime $time2, int $expectedResult) |
|
176 | |||
177 | /** @noinspection PhpDocMissingThrowsInspection */ //ReflectionException |
||
178 | /** |
||
179 | * @dataProvider localIdentifierProviderWithoutZero |
||
180 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
181 | * ::compareLocalIdentifiersWithinTournament |
||
182 | * @param mixed $localIdentifier1 the local identifier of grand parent 1 |
||
183 | * @param mixed $localIdentifier2 the local identifier of grand parent 2 |
||
184 | * @param int $expectedResult the expected result of the method |
||
185 | */ |
||
186 | public function testCompareLocalIdentifiersWithinTournamentGrandParentsLevel($localIdentifier1, $localIdentifier2, |
||
202 | |||
203 | /** @noinspection PhpDocMissingThrowsInspection */ //ReflectionException |
||
204 | /** |
||
205 | * @dataProvider localIdentifierProvider |
||
206 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
207 | * ::compareLocalIdentifiersWithinTournament |
||
208 | * @param mixed $localIdentifier1 the local identifier of entity1 |
||
209 | * @param mixed $localIdentifier2 the local identifier of entity2 |
||
210 | * @param int $expectedResult the expected result of the method |
||
211 | */ |
||
212 | View Code Duplication | public function testCompareLocalIdentifiersWithinTournamentOneLevel($localIdentifier1, $localIdentifier2, |
|
224 | |||
225 | /** @noinspection PhpDocMissingThrowsInspection */ //ReflectionException |
||
226 | /** |
||
227 | * @dataProvider localIdentifierProviderWithoutZero |
||
228 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier |
||
229 | * ::compareLocalIdentifiersWithinTournament |
||
230 | * @param mixed $localIdentifier1 the local identifier of parent 1 |
||
231 | * @param mixed $localIdentifier2 the local identifier of parent 2 |
||
232 | * @param int $expectedResult the expected result of the method |
||
233 | */ |
||
234 | public function testCompareLocalIdentifiersWithinTournamentParentsLevelWithCommonGrandParent($localIdentifier1, |
||
252 | |||
253 | /** |
||
254 | * @covers \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::__construct |
||
255 | */ |
||
256 | public function testConstruct() |
||
261 | |||
262 | /** |
||
263 | * @return array |
||
264 | */ |
||
265 | public function timePairProvider() |
||
273 | //</editor-fold desc="Public Methods"> |
||
274 | |||
275 | //<editor-fold desc="Private Methods"> |
||
276 | /** |
||
277 | * Creates a default comparer with the given timeService or with the default time service if omitted |
||
278 | * @param TimeServiceInterface|null $timeService the time service to use |
||
279 | * @return EntityComparerByTimeStartTimeAndLocalIdentifier the comparer |
||
280 | */ |
||
281 | private function createComparer(TimeServiceInterface $timeService = null) |
||
288 | |||
289 | /** |
||
290 | * Creates a tree structure entity with the given id and optionally additional method results |
||
291 | * @param string $entityId the id of the entity |
||
292 | * @param array $otherMethods the additional method results |
||
293 | * @return MockObject the stub |
||
294 | */ |
||
295 | private function createTreeStructureEntity(string $entityId, array $otherMethods = []): MockObject |
||
299 | //</editor-fold desc="Private Methods"> |
||
300 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: