Completed
Pull Request — master (#10)
by
unknown
02:54
created

CreateUserCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
rs 9.4285
cc 1
eloc 12
nc 1
nop 2
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class CreateUserCommand.
12
 */
13
class CreateUserCommand extends ContainerAwareCommand
14
{
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('sumocoders_multiuser:create')
19
            ->setDescription('Create a user entity')
20
            ->addArgument(
21
                'username',
22
                InputArgument::REQUIRED,
23
                'The username of the user'
24
            )
25
            ->addArgument(
26
                'password',
27
                InputArgument::REQUIRED,
28
                'The password for the user'
29
            )
30
            ->addArgument(
31
                'displayName',
32
                InputArgument::REQUIRED,
33
                'The display name for the user'
34
            )
35
        ;
36
    }
37
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $repository = $this->getContainer()->get('multi_user.user.repository');
41
42
        $handler = new CreateUserHandler($repository);
43
44
        $username = $input->getArgument('username');
45
        $password = $input->getArgument('password');
46
        $displayName = $input->getArgument('displayName');
47
48
        $command = new CreateUser();
49
        $command->username = $username;
50
        $command->password = $password;
51
        $command->displayName = $displayName;
52
53
        $handler->handle($command);
54
55
        $output->writeln($username . ' has been created');
56
    }
57
}
58