Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
130 | public function testMergePlayer() |
||
131 | { |
||
132 | $tournament = $this->createStub(TournamentInterface::class); |
||
133 | $player1 = $this->createStubWithId(PlayerInterface::class, "p1"); |
||
134 | $player2 = $this->createStubWithId(PlayerInterface::class, "p2"); |
||
135 | $otherPlayer = $this->createStubWithId(PlayerInterface::class, "oP"); |
||
136 | $team1Membership = $this->createStub(TeamMembershipInterface::class, ['getPlayer' => $player2]); |
||
137 | $team1Membership->method('setPlayer')->with($player1); |
||
138 | $team1 = $this->createStub(TeamInterface::class, [ |
||
139 | 'getMemberships' => new ArrayCollection([$team1Membership]) |
||
140 | ]); |
||
141 | $otherTeam = $this->createStub(TeamInterface::class, [ |
||
142 | 'getMemberships' => new ArrayCollection([$this->createStub(TeamMembershipInterface::class, [ |
||
143 | 'getPlayer' => $otherPlayer |
||
144 | ])]) |
||
145 | ]); |
||
146 | |||
147 | $game1PlayersB = new ArrayCollection([$player2->getId() => $player2]); |
||
148 | $game1 = $this->createStub(GameInterface::class, [ |
||
149 | 'getPlayersA' => new ArrayCollection([$otherPlayer->getId() => $otherPlayer]), |
||
150 | 'getPlayersB' => $game1PlayersB |
||
151 | ]); |
||
152 | |||
153 | $game2PlayersA = new ArrayCollection([$player2->getId() => $player2]); |
||
154 | $game2 = $this->createStub(GameInterface::class, [ |
||
155 | 'getPlayersA' => $game2PlayersA, |
||
156 | 'getPlayersB' => new ArrayCollection([$otherPlayer->getId() => $otherPlayer]) |
||
157 | ]); |
||
158 | |||
159 | $competition = $this->createStub(CompetitionInterface::class, [ |
||
160 | 'getTeams' => new ArrayCollection([$team1, $otherTeam]), |
||
161 | 'getPhases' => new ArrayCollection([$this->createStub(PhaseInterface::class, [ |
||
162 | 'getMatches' => new ArrayCollection([$this->createStub(MatchInterface::class, [ |
||
163 | 'getGames' => new ArrayCollection([$game1, $game2]) |
||
164 | ])]) |
||
165 | ])]) |
||
166 | ]); |
||
167 | |||
168 | |||
169 | /** @var EntityManagerInterface $em */ |
||
170 | $em = $this->getEntityManagerMockForQuery([$tournament], /** @lang DQL */ |
||
171 | "SELECT t FROM Tfboe\FmLib\Entity\TournamentInterface t INNER JOIN t.competitions c INNER JOIN c.teams te " . |
||
172 | "INNER JOIN te.memberships m WHERE m.player = (:id)"); |
||
173 | /** @var LoadingServiceInterface|MockObject $ls */ |
||
174 | $ls = $this->createMock(LoadingServiceInterface::class); |
||
175 | $ls->expects(self::once())->method('loadEntities')->with([$tournament])->willReturnCallback( |
||
176 | function ($a) use ($competition) { |
||
177 | /** @var TournamentInterface|MockObject $t */ |
||
178 | $t = $a[0]; |
||
179 | $t->method('getCompetitions')->willReturn(new ArrayCollection([$competition])); |
||
|
|||
180 | }); |
||
181 | |||
182 | /** @var RankingSystemServiceInterface|MockObject $rankingSystemService */ |
||
183 | $rankingSystemService = $this->createMock(RankingSystemServiceInterface::class); |
||
184 | $rankingSystemService->method('adaptOpenSyncFromValues')->with($tournament, []); |
||
185 | |||
186 | $service = new PlayerService($em, $ls, $rankingSystemService); |
||
187 | |||
188 | self::assertEquals(true, $service->mergePlayers($player1, $player2)); |
||
189 | |||
190 | self::assertEquals($game1PlayersB, new ArrayCollection([$player1->getId() => $player1])); |
||
191 | self::assertEquals($game2PlayersA, new ArrayCollection([$player1->getId() => $player1])); |
||
192 | } |
||
194 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.