| Total Complexity | 6 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | abstract class BaseCommand extends Command |
||
| 10 | { |
||
| 11 | protected function createUser(string $firstname, string $lastname, string $email, string $password, $roles = []) |
||
| 12 | { |
||
| 13 | $user = new User; |
||
| 14 | $user->firstname = $firstname; |
||
| 15 | $user->lastname = $lastname; |
||
| 16 | $user->email = $email; |
||
| 17 | $user->password = bcrypt($password); |
||
| 18 | $user->enabled = true; |
||
| 19 | $user->save(); |
||
| 20 | |||
| 21 | $user->assignRole((array)$roles); |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @return null|string |
||
| 26 | * @throws \Exception |
||
| 27 | */ |
||
| 28 | protected function askPassword() |
||
| 29 | { |
||
| 30 | $password = $passwordConfirm = null; |
||
| 31 | $tries = 0; |
||
| 32 | |||
| 33 | while (!$password || strlen($password) < 4 || $password != $passwordConfirm) { |
||
| 34 | if ($tries > 2) { |
||
| 35 | throw new \Exception('Aborting. Too many failed attempts to set password'); |
||
| 36 | } |
||
| 37 | |||
| 38 | $password = $this->secret('Password (min. 5 chars)'); |
||
| 39 | $passwordConfirm = $this->secret('Password (confirm)'); |
||
| 40 | |||
| 41 | $tries++; |
||
| 42 | } |
||
| 43 | |||
| 44 | return $password; |
||
| 45 | } |
||
| 47 |