We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 17 | class Parser implements ParserInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param Request $request |
||
| 21 | * |
||
| 22 | * @return array |
||
| 23 | */ |
||
| 24 | 56 | public function parse(Request $request) |
|
| 32 | |||
| 33 | /** |
||
| 34 | * Gets the body from the request based on Content-Type header. |
||
| 35 | * |
||
| 36 | * @param Request $request |
||
| 37 | * |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | 56 | private function getParsedBody(Request $request) |
|
| 41 | { |
||
| 42 | 56 | $body = $request->getContent(); |
|
| 43 | 56 | $type = explode(';', $request->headers->get('content-type'))[0]; |
|
| 44 | |||
| 45 | switch ($type) { |
||
| 46 | // Plain string |
||
| 47 | 56 | case static::CONTENT_TYPE_GRAPHQL: |
|
| 48 | 3 | $parsedBody = [static::PARAM_QUERY => $body]; |
|
| 49 | 3 | break; |
|
| 50 | |||
| 51 | // JSON object |
||
| 52 | 53 | case static::CONTENT_TYPE_JSON: |
|
| 53 | 3 | if (empty($body)) { |
|
| 54 | 1 | throw new BadRequestHttpException('The request content body must not be empty when using json content type request.'); |
|
| 55 | } |
||
| 56 | |||
| 57 | 2 | $parsedBody = json_decode($body, true); |
|
| 58 | |||
| 59 | 2 | if (JSON_ERROR_NONE !== json_last_error()) { |
|
| 60 | 1 | throw new BadRequestHttpException('POST body sent invalid JSON'); |
|
| 61 | } |
||
| 62 | 1 | break; |
|
| 63 | |||
| 64 | // URL-encoded query-string |
||
| 65 | 50 | case static::CONTENT_TYPE_FORM: |
|
| 66 | 49 | case static::CONTENT_TYPE_FORM_DATA: |
|
| 67 | 1 | $parsedBody = $request->request->all(); |
|
| 68 | 1 | break; |
|
| 69 | |||
| 70 | default: |
||
| 71 | 49 | $parsedBody = []; |
|
| 72 | 49 | break; |
|
| 73 | } |
||
| 74 | |||
| 75 | 54 | return $parsedBody; |
|
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Gets the GraphQL parameters from the request. |
||
| 80 | * |
||
| 81 | * @param Request $request |
||
| 82 | * @param array $data |
||
| 83 | * |
||
| 84 | * @return array |
||
| 85 | */ |
||
| 86 | 54 | private function getParams(Request $request, array $data = []) |
|
| 124 | } |
||
| 125 |