Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |
||
124 | public function testMergePlayer() |
||
125 | { |
||
126 | $tournament = $this->createStub(TournamentInterface::class); |
||
127 | $player1 = $this->createStubWithId(PlayerInterface::class, "p1"); |
||
128 | $player2 = $this->createStubWithId(PlayerInterface::class, "p2"); |
||
129 | $otherPlayer = $this->createStubWithId(PlayerInterface::class, "oP"); |
||
130 | $team1Membership = $this->createStub(TeamMembershipInterface::class, ['getPlayer' => $player2]); |
||
131 | $team1Membership->method('setPlayer')->with($player1); |
||
132 | $team1 = $this->createStub(TeamInterface::class, [ |
||
133 | 'getMemberships' => new ArrayCollection([$team1Membership]) |
||
134 | ]); |
||
135 | $otherTeam = $this->createStub(TeamInterface::class, [ |
||
136 | 'getMemberships' => new ArrayCollection([$this->createStub(TeamMembershipInterface::class, [ |
||
137 | 'getPlayer' => $otherPlayer |
||
138 | ])]) |
||
139 | ]); |
||
140 | |||
141 | $game1PlayersB = new ArrayCollection([$player2->getId() => $player2]); |
||
142 | $game1 = $this->createStub(GameInterface::class, [ |
||
143 | 'getPlayersA' => new ArrayCollection([$otherPlayer->getId() => $otherPlayer]), |
||
144 | 'getPlayersB' => $game1PlayersB |
||
145 | ]); |
||
146 | |||
147 | $game2PlayersA = new ArrayCollection([$player2->getId() => $player2]); |
||
148 | $game2 = $this->createStub(GameInterface::class, [ |
||
149 | 'getPlayersA' => $game2PlayersA, |
||
150 | 'getPlayersB' => new ArrayCollection([$otherPlayer->getId() => $otherPlayer]) |
||
151 | ]); |
||
152 | |||
153 | $competition = $this->createStub(CompetitionInterface::class, [ |
||
154 | 'getTeams' => new ArrayCollection([$team1, $otherTeam]), |
||
155 | 'getPhases' => new ArrayCollection([$this->createStub(PhaseInterface::class, [ |
||
156 | 'getMatches' => new ArrayCollection([$this->createStub(MatchInterface::class, [ |
||
157 | 'getGames' => new ArrayCollection([$game1, $game2]) |
||
158 | ])]) |
||
159 | ])]) |
||
160 | ]); |
||
161 | |||
162 | |||
163 | /** @var EntityManagerInterface $em */ |
||
164 | $em = $this->getEntityManagerMockForQuery([$tournament], |
||
165 | 'SELECT t FROM Tfboe\FmLib\Entity\TournamentInterface t INNER JOIN t.competitions c INNER JOIN c.teams te ' . |
||
166 | 'INNER JOIN te.memberships m WHERE m.player = (:id)'); |
||
167 | /** @var LoadingServiceInterface|MockObject $ls */ |
||
168 | $ls = $this->createMock(LoadingServiceInterface::class); |
||
169 | $ls->expects(self::once())->method('loadEntities')->with([$tournament])->willReturnCallback( |
||
170 | function ($a) use ($competition) { |
||
171 | /** @var TournamentInterface|MockObject $t */ |
||
172 | $t = $a[0]; |
||
173 | $t->method('getCompetitions')->willReturn(new ArrayCollection([$competition])); |
||
174 | }); |
||
175 | /** @var DeletionServiceInterface|MockObject $deletionService */ |
||
176 | $deletionService = $this->createMock(DeletionServiceInterface::class); |
||
177 | $deletionService->expects(self::once())->method('deletePlayer')->with($player2); |
||
178 | /** @var RankingSystemServiceInterface|MockObject $rankingSystemService */ |
||
179 | $rankingSystemService = $this->createMock(RankingSystemServiceInterface::class); |
||
180 | $rankingSystemService->method('adaptOpenSyncFromValues')->with($tournament, []); |
||
181 | |||
182 | $service = new PlayerService($em, $ls, $deletionService, $rankingSystemService); |
||
183 | |||
184 | self::assertEquals(true, $service->mergePlayers($player1, $player2)); |
||
185 | |||
186 | self::assertEquals($game1PlayersB, new ArrayCollection([$player1->getId() => $player1])); |
||
187 | self::assertEquals($game2PlayersA, new ArrayCollection([$player1->getId() => $player1])); |
||
188 | } |
||
189 | //</editor-fold desc="Public Methods"> |
||
190 | } |
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: