Code Duplication    Length = 33-34 lines in 2 locations

src/Command/ChangePasswordCommand.php 1 location

@@ 68-101 (lines=34) @@
65
    /**
66
     * {@inheritdoc}
67
     */
68
    protected function interact(InputInterface $input, OutputInterface $output)
69
    {
70
        $questions = [];
71
72
        if (!$input->getArgument('username')) {
73
            $question = new Question('Please give the username:');
74
            $question->setValidator(function ($username) {
75
                if (empty($username)) {
76
                    throw new Exception('Username can not be empty');
77
                }
78
79
                return $username;
80
            });
81
            $questions['username'] = $question;
82
        }
83
84
        if (!$input->getArgument('password')) {
85
            $question = new Question('Please enter the new password:');
86
            $question->setValidator(function ($password) {
87
                if (empty($password)) {
88
                    throw new Exception('Password can not be empty');
89
                }
90
91
                return $password;
92
            });
93
            $question->setHidden(true);
94
            $questions['password'] = $question;
95
        }
96
97
        foreach ($questions as $name => $question) {
98
            $answer = $this->getHelper('question')->ask($input, $output, $question);
99
            $input->setArgument($name, $answer);
100
        }
101
    }
102
}
103

src/Command/RoleCommand.php 1 location

@@ 76-108 (lines=33) @@
73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected function interact(InputInterface $input, OutputInterface $output)
77
    {
78
        $questions = [];
79
80
        if (!$input->getArgument('username')) {
81
            $question = new Question('Please choose a username:');
82
            $question->setValidator(function ($username) {
83
                if (empty($username)) {
84
                    throw new \Exception('Username can not be empty');
85
                }
86
87
                return $username;
88
            });
89
            $questions['username'] = $question;
90
        }
91
92
        if ((true !== $input->getOption('super')) && !$input->getArgument('role')) {
93
            $question = new Question('Please choose a role:');
94
            $question->setValidator(function ($role) {
95
                if (empty($role)) {
96
                    throw new \Exception('Role can not be empty');
97
                }
98
99
                return $role;
100
            });
101
            $questions['role'] = $question;
102
        }
103
104
        foreach ($questions as $name => $question) {
105
            $answer = $this->getHelper('question')->ask($input, $output, $question);
106
            $input->setArgument($name, $answer);
107
        }
108
    }
109
}
110