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
Pull Request — master (#137)
by Jérémiah
06:26
created

DebugCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
crap 1
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 Overblog\GraphQLBundle\Resolver\ResolverInterface;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Console\Style\SymfonyStyle;
20
21
class DebugCommand extends ContainerAwareCommand
22
{
23
    private static $categories = ['type', 'mutation', 'resolver'];
24
25 10
    protected function configure()
26
    {
27 10
        $this
28 10
            ->setName('graphql:debug')
29 10
            ->setAliases(['debug:graphql'])
30 10
            ->addOption(
31 10
                'category',
32 10
                null,
33 10
                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
34 10
                sprintf('filter by a category (%s).', implode(', ', self::$categories))
35 10
            )
36 10
            ->setDescription('Display current GraphQL services (types, resolvers and mutations)');
37 10
    }
38
39 6
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41 6
        $categoriesOption = $input->getOption('category');
42 6
        $categoriesOption = is_array($categoriesOption) ? $categoriesOption : [$categoriesOption];
43 6
        $notAllowed = array_diff($categoriesOption, self::$categories);
44 6
        if (!empty($notAllowed)) {
45 1
            throw new \InvalidArgumentException(sprintf('Invalid category (%s)', implode(',', $notAllowed)));
46
        }
47
48 5
        $categories = empty($categoriesOption) ? self::$categories : $categoriesOption;
49
50 5
        $io = new SymfonyStyle($input, $output);
51 5
        $tableHeaders = ['id', 'aliases'];
52 5
        foreach ($categories as $category) {
53 5
            $io->title(sprintf('GraphQL %ss Services', ucfirst($category)));
54
            /** @var ResolverInterface $resolver */
55 5
            $resolver = $this->getContainer()->get(sprintf('overblog_graphql.%s_resolver', $category));
56 5
            $solutions = $this->retrieveSolutions($resolver);
57 5
            $this->renderTable($tableHeaders, $solutions, $io);
58 5
        }
59 5
    }
60
61 5
    private function renderTable(array $tableHeaders, array $solutions, SymfonyStyle $io)
62
    {
63 5
        $tableRows = [];
64 5
        foreach ($solutions as $id => &$options) {
65 5
            $tableRows[] = [$id, implode("\n", $options['aliases'])];
66 5
        }
67 5
        $io->table($tableHeaders, $tableRows);
68 5
        $io->write("\n\n");
69 5
    }
70
71 5
    private function retrieveSolutions(ResolverInterface $resolver)
72
    {
73 5
        $data = [];
74 5
        foreach ($resolver->getSolutions() as $alias => $solution) {
75 5
            $options = $resolver->getSolutionOptions($alias);
76
77 5
            $id = $options['id'];
78 5
            if (!isset($data[$id]['aliases'])) {
79 5
                $data[$id]['aliases'] = [];
80 5
            }
81 5
            $data[$id]['aliases'][] = $options['alias'].(isset($options['method']) ? ' (method: '.$options['method'].')' : '');
82 5
        }
83
84 5
        return $data;
85
    }
86
87 6
    public static function getCategories()
88
    {
89 6
        return self::$categories;
90
    }
91
}
92