@@ -27,29 +27,25 @@ class SubscriberController extends AbstractController
2727 use AuthenticationTrait;
2828
2929 private SubscriberRepository $ subscriberRepository ;
30- private SerializerInterface $ serializer ;
3130
3231 /**
3332 * @param Authentication $authentication
3433 * @param SubscriberRepository $repository
35- * @param SerializerInterface $serializer
3634 */
3735 public function __construct (
3836 Authentication $ authentication ,
39- SubscriberRepository $ repository ,
40- SerializerInterface $ serializer
37+ SubscriberRepository $ repository
4138 ) {
4239 $ this ->authentication = $ authentication ;
4340 $ this ->subscriberRepository = $ repository ;
44- $ this ->serializer = $ serializer ;
4541 }
4642
4743 /**
4844 * Creates a new subscriber (if the provided data is valid and there is no subscriber with the given email
4945 * address yet).
5046 */
5147 #[Route('/subscribers ' , name: 'create_subscriber ' , methods: ['POST ' ])]
52- public function postAction (Request $ request ): JsonResponse
48+ public function postAction (Request $ request, SerializerInterface $ serializer ): JsonResponse
5349 {
5450 $ this ->requireAuthentication ($ request );
5551 $ data = $ request ->getPayload ();
@@ -59,18 +55,20 @@ public function postAction(Request $request): JsonResponse
5955 if ($ this ->subscriberRepository ->findOneByEmail ($ email ) !== null ) {
6056 throw new ConflictHttpException ('This resource already exists. ' , null , 1513439108 );
6157 }
62-
58+ // @phpstan-ignore-next-line
6359 $ subscriber = new Subscriber ();
6460 $ subscriber ->setEmail ($ email );
65- $ subscriber ->setConfirmed ((bool )$ data ->get ('confirmed ' ));
66- $ subscriber ->setBlacklisted ((bool )$ data ->get ('blacklisted ' ));
67- $ subscriber ->setHtmlEmail ((bool )$ data ->get ('html_email ' ));
68- $ subscriber ->setDisabled ((bool )$ data ->get ('disabled ' ));
61+ $ subscriber ->setConfirmed ((bool )$ data ->get ('confirmed ' , false ));
62+ $ subscriber ->setBlacklisted ((bool )$ data ->get ('blacklisted ' , false ));
63+ $ subscriber ->setHtmlEmail ((bool )$ data ->get ('html_email ' , true ));
64+ $ subscriber ->setDisabled ((bool )$ data ->get ('disabled ' , false ));
65+
6966 $ this ->subscriberRepository ->save ($ subscriber );
7067
7168 return new JsonResponse (
72- $ this ->serializer ->serialize ($ subscriber , 'json ' ),
73- Response::HTTP_CREATED , [],
69+ $ serializer ->serialize ($ subscriber , 'json ' ),
70+ Response::HTTP_CREATED ,
71+ [],
7472 true
7573 );
7674 }
0 commit comments