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

Passed
Branch master (ddaabd)
by Jérémiah
05:38
created

GraphQLDumpSchemaCommand::createFile()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 37
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
ccs 24
cts 24
cp 1
rs 8.439
cc 6
eloc 25
nc 6
nop 1
crap 6
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\Command;
13
14
use GraphQL\Type\Introspection;
15
use GraphQL\Utils\SchemaPrinter;
16
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Console\Style\SymfonyStyle;
21
22
class GraphQLDumpSchemaCommand extends ContainerAwareCommand
23
{
24 13
    protected function configure()
25
    {
26 13
        $this
27 13
            ->setName('graphql:dump-schema')
28 13
            ->setAliases(['graph:dump-schema'])
29 13
            ->setDescription('Dumps GraphQL schema')
30 13
            ->addOption(
31 13
                'file',
32 13
                null,
33 13
                InputOption::VALUE_OPTIONAL,
34
                'Path to generate schema file.'
35 13
            )
36 13
            ->addOption(
37 13
                'schema',
38 13
                null,
39 13
                InputOption::VALUE_OPTIONAL,
40
                'The schema name to generate.'
41 13
            )
42 13
            ->addOption(
43 13
                'format',
44 13
                null,
45 13
                InputOption::VALUE_OPTIONAL,
46 13
                'The schema name to generate ("graphqls" or "json").',
47
                'json'
48 13
            )
49 13
            ->addOption(
50 13
                'modern',
51 13
                null,
52 13
                InputOption::VALUE_NONE,
53
                'Enabled modern json format: { "data": { "__schema": {...} } }.'
54 13
            )
55 13
            ->addOption(
56 13
                'classic',
57 13
                null,
58 13
                InputOption::VALUE_NONE,
59
                'Enabled classic json format: { "__schema": {...} }.'
60 13
            )
61
        ;
62 13
    }
63
64 7
    protected function execute(InputInterface $input, OutputInterface $output)
65
    {
66 7
        $io = new SymfonyStyle($input, $output);
67 7
        $file = $this->createFile($input);
68 5
        $io->success(sprintf('GraphQL schema "%s" was successfully dumped.', realpath($file)));
69 5
    }
70
71 7
    private function createFile(InputInterface $input)
72
    {
73 7
        $container = $this->getContainer();
74 7
        $format = strtolower($input->getOption('format'));
75 7
        $schemaName = $input->getOption('schema');
76 7
        $requestExecutor = $container->get('overblog_graphql.request_executor');
77 7
        $file = $input->getOption('file') ?: $container->getParameter('kernel.root_dir').sprintf('/../var/schema%s.%s', $schemaName ? '.'.$schemaName : '', $format);
78
79
        switch ($format) {
80 7
            case 'json':
81
                $request = [
82 5
                    'query' => Introspection::getIntrospectionQuery(false),
83 5
                    'variables' => [],
84 5
                    'operationName' => null,
85 5
                ];
86
87 5
                $modern = $this->useModernJsonFormat($input);
88
89
                $result = $requestExecutor
90 4
                    ->execute($request, [], $schemaName)
91 4
                    ->toArray();
92
93 4
                $content = json_encode($modern ? $result : $result['data'], \JSON_PRETTY_PRINT);
94 4
                break;
95
96 2
            case 'graphqls':
97 1
                $content = SchemaPrinter::doPrint($requestExecutor->getSchema($schemaName));
98 1
                break;
99
100 1
            default:
101 1
                throw new \InvalidArgumentException(sprintf('Unknown format %s.', json_encode($format)));
102 1
        }
103
104 5
        file_put_contents($file, $content);
105
106 5
        return $file;
107
    }
108
109 5
    private function useModernJsonFormat(InputInterface $input)
110
    {
111 5
        $modern = $input->getOption('modern');
112 5
        $classic = $input->getOption('classic');
113 5
        if ($modern && $classic) {
114 1
            throw new \InvalidArgumentException('"modern" and "classic" options should not be used together.');
115
        }
116
117
        // none chosen so fallback on default behavior
118 4
        if (!$modern && !$classic) {
119 2
            return 'modern' === $this->getContainer()->getParameter('overblog_graphql.versions.relay');
120
        }
121
122 2
        return $modern;
123
    }
124
}
125