1 | <?php |
||
23 | class DeviceController extends AbstractController |
||
24 | { |
||
25 | use AuthenticationToken; |
||
26 | |||
27 | /** |
||
28 | * @var EventDispatcherInterface |
||
29 | */ |
||
30 | private $eventDispatcher; |
||
31 | |||
32 | 14 | public function __construct(EventDispatcherInterface $eventDispatcher) |
|
36 | |||
37 | /** |
||
38 | * @Route("/{serialNumber}", methods={"POST"}) |
||
39 | */ |
||
40 | 6 | public function register( |
|
41 | Request $request, |
||
42 | string $deviceLibraryIdentifier, |
||
43 | string $passTypeIdentifier, |
||
44 | string $serialNumber |
||
45 | ): JsonResponse { |
||
46 | 6 | $event = new DeviceRegisteredEvent( |
|
47 | 6 | $deviceLibraryIdentifier, |
|
48 | $passTypeIdentifier, |
||
49 | $serialNumber, |
||
50 | 6 | $this->getAuthenticationToken($request), |
|
51 | 6 | json_decode($request->getContent())->pushToken |
|
52 | ); |
||
53 | |||
54 | /** @var Status $status */ |
||
55 | 6 | $status = $this->eventDispatcher->dispatch($event)->getStatus(); |
|
|
|||
56 | |||
57 | 6 | if ($status->isUnhandled()) { |
|
58 | 1 | throw new LogicException('DeviceRegisteredEvent was not handled. Please implement a listener for this event.'); |
|
59 | } |
||
60 | |||
61 | 5 | if ($status->isNotAuthorized()) { |
|
62 | 1 | return new JsonResponse([], Response::HTTP_UNAUTHORIZED); |
|
63 | } |
||
64 | |||
65 | 4 | if ($status->isAlreadyRegistered()) { |
|
66 | 1 | return new JsonResponse([], Response::HTTP_OK); |
|
67 | } |
||
68 | |||
69 | 3 | if ($status->isSuccessful()) { |
|
70 | 2 | return new JsonResponse([], Response::HTTP_CREATED); |
|
71 | } |
||
72 | |||
73 | 1 | throw new LogicException('DeviceRegisteredEvent was not handled correctly. Unexpected status was set.'); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * @Route("/{serialNumber}", methods={"DELETE"}) |
||
78 | */ |
||
79 | 5 | public function unregister( |
|
80 | Request $request, |
||
81 | string $deviceLibraryIdentifier, |
||
82 | string $passTypeIdentifier, |
||
83 | string $serialNumber |
||
84 | ): JsonResponse { |
||
85 | 5 | $event = new DeviceUnregisteredEvent( |
|
86 | 5 | $deviceLibraryIdentifier, |
|
87 | $passTypeIdentifier, |
||
88 | $serialNumber, |
||
89 | 5 | $this->getAuthenticationToken($request) |
|
90 | ); |
||
91 | |||
92 | /** @var Status $status */ |
||
93 | 5 | $status = $this->eventDispatcher->dispatch($event)->getStatus(); |
|
94 | |||
95 | 5 | if ($status->isUnhandled()) { |
|
96 | 1 | throw new LogicException('DeviceUnregisteredEvent was not handled. Please implement a listener for this event.'); |
|
97 | } |
||
98 | |||
99 | 4 | if ($status->isNotAuthorized()) { |
|
100 | 1 | return new JsonResponse([], Response::HTTP_UNAUTHORIZED); |
|
101 | } |
||
102 | |||
103 | 3 | if ($status->isSuccessful()) { |
|
104 | 2 | return new JsonResponse([], Response::HTTP_OK); |
|
105 | } |
||
106 | |||
107 | 1 | throw new LogicException('DeviceUnregisteredEvent was not handled correctly. Unexpected status was set.'); |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * @Route("", methods={"GET"}) |
||
112 | */ |
||
113 | 6 | public function getSerialNumbers( |
|
141 | } |
||
142 |
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: