Completed
Pull Request — master (#10)
by
unknown
08:37
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
class CreateUserCommand extends ContainerAwareCommand
11
{
12
    protected function configure()
13
    {
14
        $this
15
            ->setName('sumocoders:multiuser:create')
16
            ->setDescription('Create a user entity')
17
            ->addArgument(
18
                'username',
19
                InputArgument::REQUIRED,
20
                'The username of the user'
21
            )
22
            ->addArgument(
23
                'password',
24
                InputArgument::REQUIRED,
25
                'The password for the user'
26
            )
27
            ->addArgument(
28
                'displayName',
29
                InputArgument::REQUIRED,
30
                'The display name for the user'
31
            )
32
        ;
33
    }
34
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $repository = $this->getContainer()->get('multi_user.user.repository');
38
39
        $handler = new CreateUserHandler($repository);
40
41
        $username = $input->getArgument('username');
42
        $password = $input->getArgument('password');
43
        $displayName = $input->getArgument('displayName');
44
45
        $command = new CreateUser();
46
        $command->username = $username;
47
        $command->password = $password;
48
        $command->displayName = $displayName;
49
50
        $handler->handle($command);
51
52
        $output->writeln($username . ' has been created');
53
    }
54
}
55