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 ( 497033...86dd58 )
by Jérémiah
20:42 queued 17:48
created

DebugCommand::serializeAliases()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 1
nop 2
crap 2
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 6
    public function __construct(
35
        TypeResolver $typeResolver,
36
        MutationResolver $mutationResolver,
37
        ResolverResolver $resolverResolver
38
    ) {
39 6
        parent::__construct();
40 6
        $this->typeResolver = $typeResolver;
41 6
        $this->mutationResolver = $mutationResolver;
42 6
        $this->resolverResolver = $resolverResolver;
43 6
    }
44
45 6
    protected function configure()
46
    {
47
        $this
48 6
            ->setName('graphql:debug')
49 6
            ->setAliases(['debug:graphql'])
50 6
            ->addOption(
51 6
                'category',
52 6
                null,
53 6
                InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
54 6
                sprintf('filter by a category (%s).', implode(', ', self::$categories))
55
            )
56 6
            ->setDescription('Display current GraphQL services (types, resolvers and mutations)');
57 6
    }
58
59 6
    protected function execute(InputInterface $input, OutputInterface $output)
60
    {
61 6
        $categoriesOption = $input->getOption('category');
62 6
        $categoriesOption = is_array($categoriesOption) ? $categoriesOption : [$categoriesOption];
63 6
        $notAllowed = array_diff($categoriesOption, self::$categories);
64 6
        if (!empty($notAllowed)) {
65 1
            throw new \InvalidArgumentException(sprintf('Invalid category (%s)', implode(',', $notAllowed)));
66
        }
67
68 5
        $categories = empty($categoriesOption) ? self::$categories : $categoriesOption;
69
70 5
        $io = new SymfonyStyle($input, $output);
71 5
        $tableHeaders = ['id', 'aliases'];
72 5
        foreach ($categories as $category) {
73 5
            $io->title(sprintf('GraphQL %ss Services', ucfirst($category)));
74
75
            /** @var FluentResolverInterface $resolver */
76 5
            $resolver = $this->{$category.'Resolver'};
77 5
            $this->renderTable($resolver, $tableHeaders, $io);
78
        }
79 5
    }
80
81 5
    private function renderTable(FluentResolverInterface $resolver, array $tableHeaders, SymfonyStyle $io)
82
    {
83 5
        $tableRows = [];
84 5
        $solutionIDs = array_keys($resolver->getSolutions());
85 5
        sort($solutionIDs);
86 5
        foreach ($solutionIDs as $solutionID) {
87 5
            $aliases = $resolver->getSolutionAliases($solutionID);
88 5
            $aliases[] = $solutionID;
89 5
            $options = $resolver->getSolutionOptions($solutionID);
90 5
            $tableRows[$options['id']] = [$options['id'], self::serializeAliases($aliases, $options)];
91
        }
92 5
        ksort($tableRows);
93 5
        $io->table($tableHeaders, $tableRows);
94 5
        $io->write("\n\n");
95 5
    }
96
97 5
    private static function serializeAliases(array $aliases, array $options)
98
    {
99 5
        ksort($aliases);
100 5
        $aliases = array_map(function ($alias) use ($options) {
101 5
            return $alias.(isset($options['method']) ? ' (method: '.$options['method'].')' : '');
102 5
        }, $aliases);
103
104 5
        return implode("\n", $aliases);
105
    }
106
107 6
    public static function getCategories()
108
    {
109 6
        return self::$categories;
110
    }
111
}
112