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