Code Duplication    Length = 38-38 lines in 2 locations

src/Command/DemoteUserCommand.php 1 location

@@ 21-58 (lines=38) @@
18
 * @author Antoine Hérault <[email protected]>
19
 * @author Lenar Lõhmus <[email protected]>
20
 */
21
class DemoteUserCommand extends RoleCommand
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

src/Command/PromoteUserCommand.php 1 location

@@ 23-60 (lines=38) @@
20
 * @author Luis Cordova <[email protected]>
21
 * @author Lenar Lõhmus <[email protected]>
22
 */
23
class PromoteUserCommand extends RoleCommand
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