| Conditions | 6 |
| Paths | 7 |
| Total Lines | 59 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 43 | public function __invoke(PlayerChart $playerChart, Request $request): Proof |
||
| 44 | { |
||
| 45 | $player = $this->userProvider->getPlayer(); |
||
| 46 | |||
| 47 | if ($playerChart->getPlayer() !== $player) { |
||
| 48 | throw new AccessDeniedException('ACESS DENIED'); |
||
| 49 | } |
||
| 50 | if (!in_array($playerChart->getStatus()->getId(), PlayerChartStatus::getStatusForProving())) { |
||
| 51 | throw new AccessDeniedException('ACESS DENIED'); |
||
| 52 | } |
||
| 53 | |||
| 54 | $data = json_decode($request->getContent(), true); |
||
| 55 | $url = $data['url']; |
||
| 56 | |||
| 57 | $videoIn = new Video(); |
||
| 58 | $videoIn->setUrl($url); |
||
| 59 | |||
| 60 | if (in_array($videoIn->getType(), array(VideoType::TWITCH, VideoType::YOUTUBE))) { |
||
| 61 | $video = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Video')->findOneBy( |
||
| 62 | array( |
||
| 63 | 'externalId' => $videoIn->getExternalId(), |
||
| 64 | ) |
||
| 65 | ); |
||
| 66 | |||
| 67 | if ($video == null) { |
||
| 68 | //-- Video |
||
| 69 | $video = new Video(); |
||
| 70 | $video->setUrl($url); |
||
| 71 | $video->setPlayer($player); |
||
| 72 | $video->setGame($playerChart->getChart()->getGroup()->getGame()); |
||
| 73 | $this->em->persist($video); |
||
| 74 | } |
||
| 75 | |||
| 76 | //-- Proof |
||
| 77 | $proof = new Proof(); |
||
| 78 | $proof->setVideo($video); |
||
| 79 | $proof->setPlayer($playerChart->getPlayer()); |
||
| 80 | $proof->setChart($playerChart->getChart()); |
||
| 81 | $this->em->persist($proof); |
||
| 82 | |||
| 83 | //-- PlayerChart |
||
| 84 | $playerChart->setProof($proof); |
||
| 85 | if ($playerChart->getStatus()->getId() === PlayerChartStatus::ID_STATUS_NORMAL) { |
||
| 86 | // NORMAL TO NORMAL_SEND_PROOF |
||
| 87 | $playerChart->setStatus( |
||
| 88 | $this->em->getReference(PlayerChartStatus::class, PlayerChartStatus::ID_STATUS_NORMAL_SEND_PROOF) |
||
|
|
|||
| 89 | ); |
||
| 90 | } else { |
||
| 91 | // INVESTIGATION TO DEMAND_SEND_PROOF |
||
| 92 | $playerChart->setStatus( |
||
| 93 | $this->em->getReference(PlayerChartStatus::class, PlayerChartStatus::ID_STATUS_DEMAND_SEND_PROOF) |
||
| 94 | ); |
||
| 95 | } |
||
| 96 | $this->em->flush(); |
||
| 97 | } else { |
||
| 98 | throw new BadRequestException($this->translator->trans('video.type_not_found', [], 'VgrCore')); |
||
| 99 | } |
||
| 100 | |||
| 101 | return $proof; |
||
| 102 | } |
||
| 104 |