Completed
Pull Request — master (#10)
by
unknown
05:51 queued 02:49
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 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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($user);
40
41
        $handler->handle($command);
42
43
        $output->writeln($username . ' has been deleted');
44
    }
45
}
46