Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 197e8f...ece07f )
by Jérémiah
45s
created

BatchParser::parse()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
crap 4
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\Request;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
16
17
class BatchParser implements ParserInterface
18
{
19
    const PARAM_ID = 'id';
20
21
    private static $queriesDefaultValue = [
22
        self::PARAM_ID => null,
23
        self::PARAM_QUERY => null,
24
        self::PARAM_VARIABLES => null,
25
    ];
26
27
    /**
28
     * @param Request $request
29
     *
30
     * @return array
31
     */
32 5
    public function parse(Request $request)
33
    {
34
        // Extracts the GraphQL request parameters
35 5
        $queries = $this->getParsedBody($request);
36
37 3
        if (empty($queries)) {
38 1
            throw new BadRequestHttpException('Must provide at least one valid query.');
39
        }
40
41 2
        foreach ($queries as $i => &$query) {
42 2
            $query = $query + self::$queriesDefaultValue;
43
44 2
            if (!is_string($query[static::PARAM_QUERY])) {
45 1
                throw new BadRequestHttpException(sprintf('%s is not a valid query', json_encode($query[static::PARAM_QUERY])));
46
            }
47 1
        }
48
49 1
        return $queries;
50
    }
51
52
    /**
53
     * Gets the body from the request.
54
     *
55
     * @param Request $request
56
     *
57
     * @return array
58
     */
59 5
    private function getParsedBody(Request $request)
60
    {
61 5
        $type = explode(';', $request->headers->get('content-type'))[0];
62
63
        // JSON object
64 5
        if ($type !== static::CONTENT_TYPE_JSON) {
65 1
            throw new BadRequestHttpException(sprintf('Only request with content type "%s" is accepted.', static::CONTENT_TYPE_JSON));
66
        }
67
68 4
        $parsedBody = json_decode($request->getContent(), true);
69
70 4
        if (JSON_ERROR_NONE !== json_last_error()) {
71 1
            throw new BadRequestHttpException('POST body sent invalid JSON');
72
        }
73
74 3
        return $parsedBody;
75
    }
76
}
77