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

DeleteUserCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
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 DeleteUserCommand extends ContainerAwareCommand
11
{
12
    protected function configure()
13
    {
14
        $this
15
            ->setName('sumocoders:multiuser:delete')
16
            ->setDescription('Delete a user entity')
17
            ->addArgument(
18
                'username',
19
                InputArgument::REQUIRED,
20
                'The username of the user'
21
            )
22
        ;
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $repository = $this->getContainer()->get('multi_user.user.repository');
28
29
        $handler = new DeleteUserHandler($repository);
30
31
        $username = $input->getArgument('username');
32
        $user = $repository->findByUsername($username);
33
34
        if (!$user) {
35
            $output->writeln('<error>'.$username.' doesn\'t exists');
36
            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method execute() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
37
        }
38
39
        $command = new DeleteUser();
40
        $command->user = $user;
41
42
        $handler->handle($command);
43
44
        $output->writeln($username . ' has been deleted');
45
    }
46
}
47