Completed
Pull Request — master (#10)
by
unknown
08:37
created

CreateUserCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 0
cbo 2
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 22 1
A execute() 0 19 1
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