CreateUserCommand::execute()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 26
rs 8.8571
cc 2
eloc 17
nc 2
nop 2
1
<?php
2
3
namespace DoS\UserBundle\Command;
4
5
use Sylius\Bundle\UserBundle\Command\CreateUserCommand as BaseCreateUserCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class CreateUserCommand extends BaseCreateUserCommand
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('dos:user:create')
20
            ->setDescription('Creates a new user account.')
21
            ->setDefinition(array(
22
                new InputArgument('email', InputArgument::REQUIRED, 'Email'),
23
                new InputArgument('password', InputArgument::REQUIRED, 'Password'),
24
                new InputArgument('roles', InputArgument::IS_ARRAY, 'Roles'),
25
                new InputOption('disabled', null, InputOption::VALUE_NONE, 'Set the user as a disabled user'),
26
            ))
27
            ->setHelp(<<<EOT
28
The <info>%command.name%</info> command creates a new user account.
29
EOT
30
            )
31
        ;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $email = $input->getArgument('email');
40
        $password = $input->getArgument('password');
41
        $roles = $input->getArgument('roles');
42
        $disabled = $input->getOption('disabled');
43
44
        $securityRoles = ['ROLE_USER'];
45
46
        if (!empty($roles)) {
47
            $securityRoles = array_merge($securityRoles, $roles);
48
        }
49
50
        $user = $this->createUser(
51
            $email,
52
            $password,
53
            !$disabled,
54
            array(),
55
            $securityRoles
0 ignored issues
show
Unused Code introduced by
The call to CreateUserCommand::createUser() has too many arguments starting with $securityRoles.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
56
        );
57
58
        $this->getEntityManager()->persist($user);
59
        $this->getEntityManager()->flush();
60
61
        $output->writeln(sprintf('Created user <comment>%s</comment>', $email));
62
    }
63
}
64