Completed
Pull Request — master (#13)
by
unknown
03:07
created

CreateUserCommand::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Console;
4
5
use SumoCoders\FrameworkMultiUserBundle\Command\CreateUserHandler;
6
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\Form\BaseUser;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
final class CreateUserCommand extends Command
13
{
14
    /**
15
     * @var CreateUserHandler
16
     */
17
    private $handler;
18
19
    /**
20
     * CreateUserCommand constructor.
21
     *
22
     * @param CreateUserHandler $handler
23
     */
24
    public function __construct(CreateUserHandler $handler)
25
    {
26
        parent::__construct();
27
        $this->handler = $handler;
28
    }
29
30
    protected function configure()
31
    {
32
        $this
33
            ->setName('sumocoders:multiuser:create')
34
            ->setDescription('Create a user entity')
35
            ->addArgument(
36
                'username',
37
                InputArgument::REQUIRED,
38
                'The username of the user'
39
            )
40
            ->addArgument(
41
                'password',
42
                InputArgument::REQUIRED,
43
                'The password for the user'
44
            )
45
            ->addArgument(
46
                'displayName',
47
                InputArgument::REQUIRED,
48
                'The display name for the user'
49
            )
50
            ->addArgument(
51
                'email',
52
                InputArgument::REQUIRED,
53
                'The email address for the user'
54
            )
55
        ;
56
    }
57
58
    protected function execute(InputInterface $input, OutputInterface $output)
59
    {
60
        $dataTransferObject = new BaseUser();
61
        $dataTransferObject->userName = $input->getArgument('username');
62
        $dataTransferObject->password = $input->getArgument('password');
63
        $dataTransferObject->displayName = $input->getArgument('displayName');
64
        $dataTransferObject->email = $input->getArgument('email');
65
66
        $this->handler->handle($dataTransferObject);
67
68
        $output->writeln($dataTransferObject->userName . ' has been created');
69
    }
70
}
71