1 | <?php |
||
17 | abstract class BaseApiController extends Controller |
||
18 | { |
||
19 | /** |
||
20 | * @param int $statusCode |
||
21 | * |
||
22 | * @return JsonResponse |
||
23 | */ |
||
24 | 8 | protected function createResponse($statusCode = Response::HTTP_OK) |
|
32 | |||
33 | /** |
||
34 | * Renders an successful Api call. |
||
35 | * |
||
36 | * @see renderResponse() |
||
37 | * |
||
38 | * @param Request $request |
||
39 | * @param mixed $result The result of the call. |
||
40 | * @param int $code The response code. |
||
41 | * @param array $groups JMS\Serializer groups |
||
42 | * @param array $metadata Extra metadata to put in the response |
||
43 | * @param SerializationContext $context The context to use for serializing the result data |
||
44 | * |
||
45 | * @return JsonResponse |
||
46 | */ |
||
47 | 2 | protected function renderOk(Request $request, $result, $code = 200, array $groups = [], array $metadata = [], SerializationContext $context = null) |
|
61 | |||
62 | /** |
||
63 | * Renders an Api error. |
||
64 | * |
||
65 | * @see renderResponse() |
||
66 | * |
||
67 | * @param Request $request |
||
68 | * @param int $code The response code |
||
69 | * @param string|array $error The error |
||
70 | * @param array $groups JMS\Serializer groups |
||
71 | * @param SerializationContext $context The context to use for serializing the result data |
||
72 | * |
||
73 | * @return JsonResponse |
||
74 | */ |
||
75 | 4 | protected function renderError( |
|
84 | |||
85 | /** |
||
86 | * Renders a JSON response in a generic structure: |
||
87 | * |
||
88 | * <code> |
||
89 | * { |
||
90 | * "ok": true, |
||
91 | * "result": { |
||
92 | * [...] |
||
93 | * } |
||
94 | * } |
||
95 | * </code> |
||
96 | * |
||
97 | * Or in case of an error: |
||
98 | * |
||
99 | * <code> |
||
100 | * { |
||
101 | * "ok": false, |
||
102 | * "error": "message" |
||
103 | * } |
||
104 | * </code> |
||
105 | * |
||
106 | * @param Request $request |
||
107 | * @param array $result The result of the call. |
||
108 | * @param bool $ok Whether the call was successful or not. |
||
109 | * @param int $statusCode The response code. |
||
110 | * @param array $groups JMS\Serializer groups |
||
111 | * @param SerializationContext $context The context to use for serializing the result data |
||
112 | * |
||
113 | * @return JsonResponse |
||
114 | */ |
||
115 | 6 | protected function renderResponse( |
|
162 | |||
163 | /** |
||
164 | * @param Request $request |
||
165 | * @param string $serializeType |
||
166 | * |
||
167 | * @return ParameterBag|object |
||
168 | */ |
||
169 | 4 | protected function getRequestData(Request $request, $serializeType = null) |
|
195 | |||
196 | /** |
||
197 | * Validates an API request |
||
198 | * |
||
199 | * @param object $request |
||
200 | * |
||
201 | * @throws ValidationException |
||
202 | */ |
||
203 | 3 | protected function validate($request) |
|
211 | |||
212 | /** |
||
213 | * @return UserInterface |
||
214 | */ |
||
215 | 3 | protected function getApiUser() |
|
223 | |||
224 | /** |
||
225 | * @return SecurityContext |
||
226 | */ |
||
227 | 2 | protected function getSecurityContext() |
|
231 | |||
232 | /** |
||
233 | * @return SerializerInterface |
||
234 | */ |
||
235 | 4 | protected function getSerializer() |
|
239 | |||
240 | /** |
||
241 | * @return ValidatorInterface |
||
242 | */ |
||
243 | 2 | protected function getValidator() |
|
247 | } |
||
248 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.