1 | <?php |
||
27 | class MovieRecommendationController extends BaseController |
||
28 | { |
||
29 | /** |
||
30 | * Add new recommendation. |
||
31 | * |
||
32 | * @Route("/api/movies/{id}/recommendations", methods={"POST"}) |
||
33 | * |
||
34 | * @param NewMovieRecommendationRequest $request |
||
35 | * @param Movie $originalMovie |
||
36 | * @param EntityManagerInterface $em |
||
37 | * @param ProducerInterface $producer |
||
38 | * |
||
39 | * @throws \Doctrine\ORM\ORMException |
||
40 | * |
||
41 | * @return JsonResponse |
||
42 | */ |
||
43 | 7 | public function postMoviesRecommendations(NewMovieRecommendationRequest $request, Movie $originalMovie, EntityManagerInterface $em, ProducerInterface $producer) |
|
44 | { |
||
45 | 7 | $this->denyAccessUnlessGranted(UserRoles::ROLE_USER); |
|
46 | |||
47 | 7 | $recommendation = $request->get('recommendation'); |
|
48 | 7 | $user = $this->getUser(); |
|
49 | |||
50 | 7 | if (empty($recommendation['movie_id'])) { |
|
51 | 1 | $message = new Message(json_encode([ |
|
52 | 1 | 'tmdb_id' => $recommendation['tmdb_id'], |
|
53 | 1 | 'movie_id' => $originalMovie->getId(), |
|
54 | 1 | 'user_id' => $user->getId(), |
|
55 | ])); |
||
56 | // todo redis doesnt support priority $message->setPriority(MessagePriority::VERY_LOW); |
||
57 | 1 | $producer->sendEvent(AddRecommendationProcessor::ADD_RECOMMENDATION, $message); |
|
58 | |||
59 | 1 | return new JsonResponse(); |
|
60 | } |
||
61 | |||
62 | 6 | $recommendedMovie = $em->getReference(Movie::class, $recommendation['movie_id']); |
|
63 | |||
64 | 6 | if ($recommendedMovie === null) { |
|
65 | throw new NotFoundHttpException(); |
||
66 | } |
||
67 | |||
68 | 6 | $originalMovie->addRecommendation($user, $recommendedMovie); |
|
|
|||
69 | 6 | $em->persist($originalMovie); |
|
70 | try { |
||
71 | 6 | $em->flush(); |
|
72 | } catch (UniqueConstraintViolationException $exception) { |
||
73 | // It's ok.. |
||
74 | } |
||
75 | |||
76 | 6 | return new JsonResponse(); |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Remove recommendation. |
||
81 | * |
||
82 | * @Route("/api/movies/{id}/recommendations", methods={"DELETE"}) |
||
83 | * |
||
84 | * @param RemoveMovieRecommendationRequest $request |
||
85 | * @param Movie $originalMovie |
||
86 | * @param MovieRecommendationRepository $repository |
||
87 | * @param EntityManagerInterface $em |
||
88 | * |
||
89 | * @return JsonResponse |
||
90 | */ |
||
91 | public function deleteMoviesRecommendations(RemoveMovieRecommendationRequest $request, Movie $originalMovie, MovieRecommendationRepository $repository, EntityManagerInterface $em) |
||
119 | |||
120 | private function findRecommendedMovieById(Movie $originalMovie, User $user, int $id): ?MovieRecommendation |
||
130 | |||
131 | private function findRecommendedMovieByTmdbId(Movie $originalMovie, User $user, int $tmdbId): ?MovieRecommendation |
||
141 | |||
142 | /** |
||
143 | * @Route("/api/movies/{id}/recommendations", methods={"GET"}) |
||
144 | * |
||
145 | * @param Request $request |
||
146 | * @param Movie $movie |
||
147 | * @param MovieRecommendationRepository $repository |
||
148 | * |
||
149 | * @return JsonResponse |
||
150 | */ |
||
151 | 3 | public function getMoviesRecommendations(Request $request, Movie $movie, MovieRecommendationRepository $repository) |
|
170 | |||
171 | /** |
||
172 | * Get movies by title. |
||
173 | * |
||
174 | * @Route("/api/movies/{id}/recommendations/search", methods={"POST"}) |
||
175 | * |
||
176 | * @param int $id |
||
177 | * @param SearchRequest $request |
||
178 | * @param SearchService $searchService |
||
179 | * @param Request $currentRequest |
||
180 | * |
||
181 | * @throws \App\Movies\Exception\TmdbMovieNotFoundException |
||
182 | * @throws \App\Movies\Exception\TmdbRequestLimitException |
||
183 | * @throws \ErrorException |
||
184 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
185 | * |
||
186 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
187 | */ |
||
188 | public function getSearch(int $id, SearchRequest $request, SearchService $searchService, Request $currentRequest) |
||
205 | } |
||
206 |
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: