CreateClientCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
nc 1
cc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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 App\Command\OauthServer;
13
14
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use App\Entity\OAuth\Client;
20
21
class CreateClientCommand extends Command
22
{
23
    /**
24
     * @var ClientManagerInterface
25
     */
26
    private $clientManager;
27
28
    /**
29
     * @param ClientManagerInterface $clientManager
30
     */
31
    public function __construct(ClientManagerInterface $clientManager)
32
    {
33
        $this->clientManager = $clientManager;
34
35
        parent::__construct();
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function configure()
42
    {
43
        $this
44
            ->setName('sylius:oauth-server:create-client')
45
            ->setDescription('Creates a new client')
46
            ->addOption(
47
                'redirect-uri',
48
                null,
49
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
50
                'Sets redirect uri for client.'
51
            )
52
            ->addOption(
53
                'grant-type',
54
                null,
55
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
56
                'Sets allowed grant type for client.'
57
            )
58
            ->setHelp(<<<EOT
59
The <info>%command.name%</info>command creates a new client.
60
<info>php %command.full_name% [--redirect-uri=...] [--grant-type=...] name</info>
61
EOT
62
            );
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    protected function execute(InputInterface $input, OutputInterface $output)
69
    {
70
        /** @var Client $client */
71
        $client = $this->clientManager->createClient();
72
        $client->setRedirectUris($input->getOption('redirect-uri'));
73
        $client->setAllowedGrantTypes($input->getOption('grant-type'));
74
        $this->clientManager->updateClient($client);
75
76
        $output->writeln(
77
            sprintf(
78
                'A new client with public id <info>%s</info>, secret <info>%s</info> has been added',
79
                $client->getPublicId(),
80
                $client->getSecret()
81
            )
82
        );
83
84
        return 0;
85
    }
86
}
87