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

DeleteUserCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 0 21 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 DeleteUserCommand.
12
 */
13
class DeleteUserCommand extends ContainerAwareCommand
14
{
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('sumocoders_multiuser:delete')
19
            ->setDescription('Delete a user entity')
20
            ->addArgument(
21
                'username',
22
                InputArgument::REQUIRED,
23
                'The username of the user'
24
            )
25
        ;
26
    }
27
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $repository = $this->getContainer()->get('multi_user.user.repository');
31
32
        $handler = new DeleteUserHandler($repository);
33
34
        $username = $input->getArgument('username');
35
        $user = $repository->findByUsername($username);
36
37
        if (!$user) {
38
            $output->writeln('<error>'.$username.' doesn\'t exists');
39
            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...
40
        }
41
42
        $command = new DeleteUser();
43
        $command->user = $user;
44
45
        $handler->handle($command);
46
47
        $output->writeln($username . ' has been deleted');
48
    }
49
}
50