| @@ 106-126 (lines=21) @@ | ||
| 103 | * |
|
| 104 | * @return User |
|
| 105 | */ |
|
| 106 | protected function editUsername( |
|
| 107 | InputInterface $input, |
|
| 108 | OutputInterface $output, |
|
| 109 | User $user, |
|
| 110 | QuestionHelper $questionHelper |
|
| 111 | ) { |
|
| 112 | $realNameQuestion = new Question('Username [required]: '); |
|
| 113 | $realNameQuestion->setValidator( |
|
| 114 | function ($answer) { |
|
| 115 | if (empty($answer)) { |
|
| 116 | throw new \RuntimeException('Username must not be empty'); |
|
| 117 | } |
|
| 118 | ||
| 119 | return $answer; |
|
| 120 | } |
|
| 121 | ); |
|
| 122 | $realNameQuestion->setMaxAttempts(2); |
|
| 123 | $user->setUsername($questionHelper->ask($input, $output, $realNameQuestion)); |
|
| 124 | ||
| 125 | return $user; |
|
| 126 | } |
|
| 127 | ||
| 128 | /** |
|
| 129 | * @param InputInterface $input |
|
| @@ 136-156 (lines=21) @@ | ||
| 133 | * |
|
| 134 | * @return User |
|
| 135 | */ |
|
| 136 | protected function editRealName( |
|
| 137 | InputInterface $input, |
|
| 138 | OutputInterface $output, |
|
| 139 | User $user, |
|
| 140 | QuestionHelper $questionHelper |
|
| 141 | ) { |
|
| 142 | $realNameQuestion = new Question('Real Name [required]: '); |
|
| 143 | $realNameQuestion->setValidator( |
|
| 144 | function ($answer) { |
|
| 145 | if (empty($answer)) { |
|
| 146 | throw new \RuntimeException('Real Name must not be empty'); |
|
| 147 | } |
|
| 148 | ||
| 149 | return $answer; |
|
| 150 | } |
|
| 151 | ); |
|
| 152 | $realNameQuestion->setMaxAttempts(2); |
|
| 153 | $user->setRealName($questionHelper->ask($input, $output, $realNameQuestion)); |
|
| 154 | ||
| 155 | return $user; |
|
| 156 | } |
|
| 157 | ||
| 158 | /** |
|
| 159 | * @param InputInterface $input |
|
| @@ 166-186 (lines=21) @@ | ||
| 163 | * |
|
| 164 | * @return User |
|
| 165 | */ |
|
| 166 | protected function editEmail( |
|
| 167 | InputInterface $input, |
|
| 168 | OutputInterface $output, |
|
| 169 | User $user, |
|
| 170 | QuestionHelper $questionHelper |
|
| 171 | ) { |
|
| 172 | $emailQuestion = new Question('Email [required]: '); |
|
| 173 | $emailQuestion->setValidator( |
|
| 174 | function ($answer) { |
|
| 175 | if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) { |
|
| 176 | throw new \RuntimeException("This is not a valid email address"); |
|
| 177 | } |
|
| 178 | ||
| 179 | return $answer; |
|
| 180 | } |
|
| 181 | ); |
|
| 182 | $emailQuestion->setMaxAttempts(2); |
|
| 183 | $user->setEmail($questionHelper->ask($input, $output, $emailQuestion)); |
|
| 184 | ||
| 185 | return $user; |
|
| 186 | } |
|
| 187 | ||
| 188 | /** |
|
| 189 | * @param InputInterface $input |
|