DemoteUserCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 38
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 15 15 1
A executeRoleCommand() 13 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Silex\User\Command;
13
14
use AWurth\Silex\User\Util\UserManipulator;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * @author Antoine Hérault <[email protected]>
19
 * @author Lenar Lõhmus <[email protected]>
20
 */
21 View Code Duplication
class DemoteUserCommand 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...
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function configure()
27
    {
28
        parent::configure();
29
30
        $this
31
            ->setName('silex-user:demote')
32
            ->setDescription('Demote a user by removing a role')
33
            ->setHelp(<<<'EOT'
34
The <info>silex-user:demote</info> command demotes a user by removing a role
35
36
  <info>php %command.full_name% matthieu ROLE_CUSTOM</info>
37
  <info>php %command.full_name% --super matthieu</info>
38
EOT
39
            );
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function executeRoleCommand(UserManipulator $manipulator, OutputInterface $output, $username, $super, $role)
46
    {
47
        if ($super) {
48
            $manipulator->demote($username);
49
            $output->writeln(sprintf('User "%s" has been demoted as a simple user. This change will not apply until the user logs out and back in again.', $username));
50
        } else {
51
            if ($manipulator->removeRole($username, $role)) {
52
                $output->writeln(sprintf('Role "%s" has been removed from user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
53
            } else {
54
                $output->writeln(sprintf('User "%s" didn\'t have "%s" role.', $username, $role));
55
            }
56
        }
57
    }
58
}
59