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
Push — master ( cc83a8...7c2c4f )
by Jérémiah
48s
created

DebugCommand   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 5
dl 0
loc 73
ccs 51
cts 51
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
B execute() 0 21 5
A renderTable() 0 10 2
A retrieveSolutions() 0 16 4
A getCategories() 0 4 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
            ksort($options['aliases']);
66 5
            $tableRows[] = [$id, implode("\n", $options['aliases'])];
67 5
        }
68 5
        $io->table($tableHeaders, $tableRows);
69 5
        $io->write("\n\n");
70 5
    }
71
72 5
    private function retrieveSolutions(ResolverInterface $resolver)
73
    {
74 5
        $data = [];
75 5
        foreach ($resolver->getSolutions() as $alias => $solution) {
76 5
            $options = $resolver->getSolutionOptions($alias);
77
78 5
            $id = $options['id'];
79 5
            if (!isset($data[$id]['aliases'])) {
80 5
                $data[$id]['aliases'] = [];
81 5
            }
82 5
            $data[$id]['aliases'][] = $options['alias'].(isset($options['method']) ? ' (method: '.$options['method'].')' : '');
83 5
        }
84 5
        ksort($data);
85
86 5
        return $data;
87
    }
88
89 6
    public static function getCategories()
90
    {
91 6
        return self::$categories;
92
    }
93
}
94