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 (#333)
by Jérémiah
08:28 queued 05:48
created

DebugCommand   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 0
loc 98
ccs 0
cts 62
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A configure() 0 13 1
A execute() 0 22 5
A renderTable() 0 13 2
A serializeAliases() 0 6 1
A getCategories() 0 4 1
1
<?php
2
3
namespace Overblog\GraphQLBundle\Command;
4
5
use Overblog\GraphQLBundle\Resolver\FluentResolverInterface;
6
use Overblog\GraphQLBundle\Resolver\MutationResolver;
7
use Overblog\GraphQLBundle\Resolver\ResolverResolver;
8
use Overblog\GraphQLBundle\Resolver\TypeResolver;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
class DebugCommand extends Command
16
{
17
    private static $categories = ['type', 'mutation', 'resolver'];
18
19
    /**
20
     * @var TypeResolver
21
     */
22
    private $typeResolver;
23
24
    /**
25
     * @var MutationResolver
26
     */
27
    private $mutationResolver;
28
29
    /**
30
     * @var ResolverResolver
31
     */
32
    private $resolverResolver;
33
34
    public function __construct(
35
        TypeResolver $typeResolver,
36
        MutationResolver $mutationResolver,
37
        ResolverResolver $resolverResolver
38
    ) {
39
        parent::__construct();
40
        $this->typeResolver = $typeResolver;
41
        $this->mutationResolver = $mutationResolver;
42
        $this->resolverResolver = $resolverResolver;
43
    }
44
45
    protected function configure()
46
    {
47
        $this
48
            ->setName('graphql:debug')
49
            ->setAliases(['debug:graphql'])
50
            ->addOption(
51
                'category',
52
                null,
53
                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
54
                sprintf('filter by a category (%s).', implode(', ', self::$categories))
55
            )
56
            ->setDescription('Display current GraphQL services (types, resolvers and mutations)');
57
    }
58
59
    protected function execute(InputInterface $input, OutputInterface $output)
60
    {
61
        $categoriesOption = $input->getOption('category');
62
        $categoriesOption = is_array($categoriesOption) ? $categoriesOption : [$categoriesOption];
63
        $notAllowed = array_diff($categoriesOption, self::$categories);
64
        if (!empty($notAllowed)) {
65
            throw new \InvalidArgumentException(sprintf('Invalid category (%s)', implode(',', $notAllowed)));
66
        }
67
68
        $categories = empty($categoriesOption) ? self::$categories : $categoriesOption;
69
70
        $io = new SymfonyStyle($input, $output);
71
        $tableHeaders = ['solution id', 'aliases'];
72
73
        foreach ($categories as $category) {
74
            $io->title(sprintf('GraphQL %ss Services', ucfirst($category)));
75
76
            /** @var FluentResolverInterface $resolver */
77
            $resolver = $this->{$category.'Resolver'};
78
            $this->renderTable($resolver, $tableHeaders, $io);
79
        }
80
    }
81
82
    /**
83
     * @param FluentResolverInterface $resolver
84
     * @param array                   $tableHeaders
85
     * @param SymfonyStyle            $io
86
     */
87
    private function renderTable(FluentResolverInterface $resolver, array $tableHeaders, SymfonyStyle $io)
88
    {
89
        $tableRows = [];
90
        $solutionIDs = array_keys($resolver->getSolutions());
91
        sort($solutionIDs);
92
        foreach ($solutionIDs as $solutionID) {
93
            $aliases = $resolver->getSolutionAliases($solutionID);
94
            $tableRows[$solutionID] = [$solutionID, self::serializeAliases($aliases)];
95
        }
96
        ksort($tableRows);
97
        $io->table($tableHeaders, $tableRows);
98
        $io->write("\n\n");
99
    }
100
101
    private static function serializeAliases(array $aliases)
102
    {
103
        ksort($aliases);
104
105
        return implode("\n", $aliases);
106
    }
107
108
    public static function getCategories()
109
    {
110
        return self::$categories;
111
    }
112
}
113