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 Antoine Hérault <[email protected]> |
19
|
|
|
* @author Lenar Lõhmus <[email protected]> |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
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
|
|
|
|
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.