aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Friedman <maf675@gmail.com>2016-03-09 15:16:23 -0800
committerMatt Friedman <maf675@gmail.com>2016-03-09 15:16:23 -0800
commit693664f278e0d99efef9e81c3848fe3f7edf9e7f (patch)
treefbb8fb6bfaf4afa46fc6058cf6647fe50f2d257f
parent00bf1ef8b89b8dbae0a22bf3d8b3536d5226f32d (diff)
downloadforums-693664f278e0d99efef9e81c3848fe3f7edf9e7f.tar
forums-693664f278e0d99efef9e81c3848fe3f7edf9e7f.tar.gz
forums-693664f278e0d99efef9e81c3848fe3f7edf9e7f.tar.bz2
forums-693664f278e0d99efef9e81c3848fe3f7edf9e7f.tar.xz
forums-693664f278e0d99efef9e81c3848fe3f7edf9e7f.zip
[ticket/12684] Extract interactivity to a method
PHPBB3-12684
-rw-r--r--phpBB/phpbb/console/command/user/add.php89
1 files changed, 52 insertions, 37 deletions
diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php
index a0da15915d..8151f3827c 100644
--- a/phpBB/phpbb/console/command/user/add.php
+++ b/phpBB/phpbb/console/command/user/add.php
@@ -125,43 +125,7 @@ class add extends \phpbb\console\command\command
{
$io = new SymfonyStyle($input, $output);
- $helper = $this->getHelper('question');
-
- $data = array(
- 'username' => $input->getOption('username'),
- 'new_password' => $input->getOption('password'),
- 'email' => $input->getOption('email'),
- );
-
- if (!$data['username'])
- {
- $question = new Question($this->ask_user('USERNAME'));
- $data['username'] = $helper->ask($input, $output, $question);
- }
-
- if (!$data['new_password'])
- {
- $question = new Question($this->ask_user('PASSWORD'));
- $question->setValidator(function ($value) use ($helper, $input, $output) {
- $question = new Question($this->ask_user('CONFIRM_PASSWORD'));
- $question->setHidden(true);
- if ($helper->ask($input, $output, $question) != $value)
- {
- throw new runtime_exception($this->language->lang('NEW_PASSWORD_ERROR'));
- }
- return $value;
- });
- $question->setHidden(true);
- $question->setMaxAttempts(5);
-
- $data['new_password'] = $helper->ask($input, $output, $question);
- }
-
- if (!$data['email'])
- {
- $question = new Question($this->ask_user('EMAIL_ADDRESS'));
- $data['email'] = $helper->ask($input, $output, $question);
- }
+ $data = $this->interact($input, $output);
try
{
@@ -204,6 +168,57 @@ class add extends \phpbb\console\command\command
}
/**
+ * Interact with the user to obtain the required options
+ *
+ * @param InputInterface $input The input stream used to get the options
+ * @param OutputInterface $output The output stream, used to print messages
+ *
+ * @return array Array of required user options
+ */
+ protected function interact(InputInterface $input, OutputInterface $output)
+ {
+ $helper = $this->getHelper('question');
+
+ $data = array(
+ 'username' => $input->getOption('username'),
+ 'new_password' => $input->getOption('password'),
+ 'email' => $input->getOption('email'),
+ );
+
+ if (!$data['username'])
+ {
+ $question = new Question($this->ask_user('USERNAME'));
+ $data['username'] = $helper->ask($input, $output, $question);
+ }
+
+ if (!$data['new_password'])
+ {
+ $question = new Question($this->ask_user('PASSWORD'));
+ $question->setValidator(function ($value) use ($helper, $input, $output) {
+ $question = new Question($this->ask_user('CONFIRM_PASSWORD'));
+ $question->setHidden(true);
+ if ($helper->ask($input, $output, $question) != $value)
+ {
+ throw new runtime_exception($this->language->lang('NEW_PASSWORD_ERROR'));
+ }
+ return $value;
+ });
+ $question->setHidden(true);
+ $question->setMaxAttempts(5);
+
+ $data['new_password'] = $helper->ask($input, $output, $question);
+ }
+
+ if (!$data['email'])
+ {
+ $question = new Question($this->ask_user('EMAIL_ADDRESS'));
+ $data['email'] = $helper->ask($input, $output, $question);
+ }
+
+ return $data;
+ }
+
+ /**
* Validate the submitted user data
*
* @param array $data The user data array