Failed Conditions
Branch issue#666 (91903a)
by Guilherme
08:25
created

ClientCreateCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
A execute() 0 11 1
1
<?php
2
3
namespace LoginCidadao\OAuthBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use LoginCidadao\OAuthBundle\Entity\Client;
11
12
class ClientCreateCommand extends ContainerAwareCommand
13
{
14
15
    protected function configure()
16
    {
17
        $this
18
                ->setName('lc:oauth-server:client:create')
19
                ->setDescription('Creates a new client')
20
                ->addArgument('name', InputArgument::REQUIRED, 'Sets the client name', null)
21
                ->addArgument('description', InputArgument::REQUIRED, 'Sets the client description', null)
22
                ->addArgument('site-url', InputArgument::REQUIRED, 'Sets the client main URL', null)
23
                ->addOption('redirect-uri', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Sets redirect uri for client. Use this option multiple times to set multiple redirect URIs.', null)
24
                ->addOption('grant-type', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Sets allowed grant type for client. Use this option multiple times to set multiple grant types..', null)
25
                ->setHelp(<<<EOT
26
The <info>%command.name%</info>command creates a new client.
27
28
  <info>php %command.full_name% [--redirect-uri=...] [--grant-type=...] name</info>
29
30
EOT
31
        );
32
    }
33
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $clientManager = $this->getContainer()->get('fos_oauth_server.client_manager');
37
        $client = $clientManager->createClient();
38
        $client->setName($input->getArgument('name'));
39
        $client->setDescription($input->getArgument('description'));
40
        $client->setSiteUrl($input->getArgument('site-url'));
41
        $client->setRedirectUris($input->getOption('redirect-uri'));
42
        $client->setAllowedGrantTypes($input->getOption('grant-type'));
43
        $clientManager->updateClient($client);
44
        $output->writeln(sprintf('Added a new client with name <info>%s</info> and public id <info>%s</info>.', $client->getName(), $client->getPublicId()));
45
    }
46
47
}
48