CreateClientCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Question\ChoiceQuestion;
11
use Symfony\Component\Console\Question\Question;
12
use Symfony\Component\Console\Style\SymfonyStyle;
13
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
14
use Symfony\Component\DependencyInjection\ContainerInterface;
15
16
class CreateClientCommand extends Command
17
{
18
    protected static $defaultName = 'api:client:create';
19
20
    /**
21
     * @var ContainerInterface
22
     */
23
    private $container;
24
25
    /**
26
     * ApiCreateClientCommand constructor.
27
     * @param ContainerInterface $container
28
     */
29 2
    public function __construct(ContainerInterface $container)
30
    {
31 2
        $this->container = $container;
32 2
        parent::__construct();
33 2
    }
34
35
    /**
36
     *
37
     */
38 2
    protected function configure()
39
    {
40
        $this
41 2
            ->setName('api:client:create')
42 2
            ->setDescription('Creates a new client');
43 2
    }
44
45
    /**
46
     * @param InputInterface $input
47
     * @param OutputInterface $output
48
     * @return int|null|void
49
     */
50 2
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52 2
        $helper = $this->getHelper('question');
53 2
        $question = new ChoiceQuestion(
54 2
            'Please select your desired grant types)', [
55 2
                'authorization_code',
56
                'client_credentials',
57
                'password',
58
                'refresh_token'
59
            ]
60
        );
61 2
        $question->setMultiselect(true);
62
63 2
        $types = $helper->ask($input, $output, $question);
64 2
        $output->writeln('You\'ve enabled: ' . implode(', ', $types));
65
66 2
        $question = new Question("Please enter your redirect uris. Separate multiple with commas: \n");
67 2
        $redirectUris = $helper->ask($input, $output, $question);
68
69 2
        $clientManager = $this->container->get('api.client_manager.default');
70 2
        $client = $clientManager->createClient();
71 2
        if(strpos($redirectUris, ',') !== false) {
72 1
            $client->setRedirectUris(explode(',', $redirectUris));
73
        }
74
        else {
75 1
            $client->setRedirectUris([$redirectUris]);
76
        }
77 2
        $client->setAllowedGrantTypes($types);
78 2
        $clientManager->updateClient($client);
79 2
        $output->writeln(
80 2
            sprintf(
81 2
                'Added a new client with public id <info>%s</info>, secret <info>%s</info>',
82 2
                $client->getPublicId(),
83 2
                $client->getSecret()
84
            )
85
        );
86 2
    }
87
88
}
89