55use BenTools \WebPushBundle \Model \Subscription \UserSubscriptionManagerRegistry ;
66use Symfony \Component \HttpFoundation \Request ;
77use Symfony \Component \HttpFoundation \Response ;
8+ use Symfony \Component \HttpKernel \Exception \AccessDeniedHttpException ;
89use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
910use Symfony \Component \HttpKernel \Exception \MethodNotAllowedHttpException ;
1011use Symfony \Component \Security \Core \User \UserInterface ;
@@ -18,18 +19,13 @@ final class RegisterSubscriptionAction
1819
1920 /**
2021 * RegisterSubscriptionAction constructor.
21- * @param UserSubscriptionManagerRegistry $registry
2222 */
2323 public function __construct (UserSubscriptionManagerRegistry $ registry )
2424 {
2525 $ this ->registry = $ registry ;
2626 }
2727
2828 /**
29- * @param UserInterface $user
30- * @param string $subscriptionHash
31- * @param array $subscription
32- * @param array $options
3329 * @throws \InvalidArgumentException
3430 * @throws \RuntimeException
3531 * @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
@@ -44,8 +40,6 @@ private function subscribe(UserInterface $user, string $subscriptionHash, array
4440 }
4541
4642 /**
47- * @param UserInterface $user
48- * @param string $subscriptionHash
4943 * @throws BadRequestHttpException
5044 * @throws \RuntimeException
5145 */
@@ -54,18 +48,16 @@ private function unsubscribe(UserInterface $user, string $subscriptionHash)
5448 $ manager = $ this ->registry ->getManager ($ user );
5549 $ subscription = $ manager ->getUserSubscription ($ user , $ subscriptionHash );
5650 if (null === $ subscription ) {
57- throw new BadRequestHttpException (" Subscription hash not found " );
51+ throw new BadRequestHttpException (' Subscription hash not found ' );
5852 }
5953 $ manager ->delete ($ subscription );
6054 }
6155
62- /**
63- * @param Request $request
64- * @param UserInterface $user
65- * @return Response
66- */
67- public function __invoke (Request $ request , UserInterface $ user ): Response
56+ public function __invoke (Request $ request , UserInterface $ user = null ): Response
6857 {
58+ if (null === $ user ) {
59+ throw new AccessDeniedHttpException ('Not authenticated. ' );
60+ }
6961
7062 if (!in_array ($ request ->getMethod (), ['POST ' , 'DELETE ' ])) {
7163 throw new MethodNotAllowedHttpException (['POST ' , 'DELETE ' ]);
0 commit comments