Code Duplication    Length = 54-54 lines in 2 locations

src/Command/ActivateUserCommand.php 1 location

@@ 22-75 (lines=54) @@
19
/**
20
 * @author Antoine Hérault <[email protected]>
21
 */
22
class ActivateUserCommand extends ContainerAwareCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        $this
30
            ->setName('silex-user:activate')
31
            ->setDescription('Activate a user')
32
            ->setDefinition([
33
                new InputArgument('username', InputArgument::REQUIRED, 'The username')
34
            ])
35
            ->setHelp(<<<'EOT'
36
The <info>silex-user:activate</info> command activates a user (so they will be able to log in):
37
38
  <info>php %command.full_name% matthieu</info>
39
EOT
40
            );
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $username = $input->getArgument('username');
49
50
        $manipulator = $this->container['silex_user.util.user_manipulator'];
51
        $manipulator->activate($username);
52
53
        $output->writeln(sprintf('User "%s" has been activated.', $username));
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function interact(InputInterface $input, OutputInterface $output)
60
    {
61
        if (!$input->getArgument('username')) {
62
            $question = new Question('Please choose a username:');
63
            $question->setValidator(function ($username) {
64
                if (empty($username)) {
65
                    throw new \Exception('Username can not be empty');
66
                }
67
68
                return $username;
69
            });
70
            $answer = $this->getHelper('question')->ask($input, $output, $question);
71
72
            $input->setArgument('username', $answer);
73
        }
74
    }
75
}
76

src/Command/DeactivateUserCommand.php 1 location

@@ 22-75 (lines=54) @@
19
/**
20
 * @author Antoine Hérault <[email protected]>
21
 */
22
class DeactivateUserCommand extends ContainerAwareCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        $this
30
            ->setName('silex-user:deactivate')
31
            ->setDescription('Deactivate a user')
32
            ->setDefinition([
33
                new InputArgument('username', InputArgument::REQUIRED, 'The username')
34
            ])
35
            ->setHelp(<<<'EOT'
36
The <info>silex-user:deactivate</info> command deactivates a user (will not be able to log in)
37
38
  <info>php %command.full_name% matthieu</info>
39
EOT
40
            );
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $username = $input->getArgument('username');
49
50
        $manipulator = $this->container['silex_user.util.user_manipulator'];
51
        $manipulator->deactivate($username);
52
53
        $output->writeln(sprintf('User "%s" has been deactivated.', $username));
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function interact(InputInterface $input, OutputInterface $output)
60
    {
61
        if (!$input->getArgument('username')) {
62
            $question = new Question('Please choose a username:');
63
            $question->setValidator(function ($username) {
64
                if (empty($username)) {
65
                    throw new \Exception('Username can not be empty');
66
                }
67
68
                return $username;
69
            });
70
            $answer = $this->getHelper('question')->ask($input, $output, $question);
71
72
            $input->setArgument('username', $answer);
73
        }
74
    }
75
}
76