Completed
Push — master ( 82bcf8...197f8d )
by Alexis
03:41
created

PromoteUserCommand::executeRoleCommand()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 5
1
<?php
2
3
/*
4
 * This file is part of the awurth/silex-user package.
5
 *
6
 * (c) Alexis Wurth <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AWurth\SilexUser\Command;
13
14
use AWurth\SilexUser\Util\UserManipulator;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * @author Matthieu Bontemps <[email protected]>
19
 * @author Thibault Duplessis <[email protected]>
20
 * @author Luis Cordova <[email protected]>
21
 * @author Lenar Lõhmus <[email protected]>
22
 */
23 View Code Duplication
class PromoteUserCommand extends RoleCommand
0 ignored issues
show
Duplication introduced by
This class 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...
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function configure()
29
    {
30
        parent::configure();
31
32
        $this
33
            ->setName('silex-user:promote')
34
            ->setDescription('Promotes a user by adding a role')
35
            ->setHelp(<<<'EOT'
36
The <info>silex-user:promote</info> command promotes a user by adding a role
37
38
  <info>php %command.full_name% matthieu ROLE_CUSTOM</info>
39
  <info>php %command.full_name% --super matthieu</info>
40
EOT
41
            );
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function executeRoleCommand(UserManipulator $manipulator, OutputInterface $output, $username, $super, $role)
48
    {
49
        if ($super) {
50
            $manipulator->promote($username);
51
            $output->writeln(sprintf('User "%s" has been promoted as a super administrator. This change will not apply until the user logs out and back in again.', $username));
52
        } else {
53
            if ($manipulator->addRole($username, $role)) {
54
                $output->writeln(sprintf('Role "%s" has been added to user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
55
            } else {
56
                $output->writeln(sprintf('User "%s" did already have "%s" role.', $username, $role));
57
            }
58
        }
59
    }
60
}
61