| Conditions | 3 |
| Paths | 3 |
| Total Lines | 56 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 58 | public function handle() |
||
| 59 | { |
||
| 60 | $name = $this->ask('What is your name? '); |
||
| 61 | $email = $this->ask('What is your email? '); |
||
| 62 | $password = $this->secret('Enter a password '); |
||
| 63 | |||
| 64 | // Validate user input |
||
| 65 | $this->info('Validating your information and generating a new user...'); |
||
| 66 | |||
| 67 | $data = [ |
||
| 68 | 'name' => $name, |
||
| 69 | 'email' => $email, |
||
| 70 | 'password' => $password, |
||
| 71 | ]; |
||
| 72 | |||
| 73 | $rules = [ |
||
| 74 | 'name' => 'required|max:185', |
||
| 75 | 'email' => 'required|email', |
||
| 76 | 'password' => 'required|min:8', |
||
| 77 | ]; |
||
| 78 | |||
| 79 | $validator = \Validator::make($data, $rules); |
||
| 80 | |||
| 81 | if ($validator->fails()) { |
||
| 82 | $messages = $validator->errors(); |
||
| 83 | foreach ($messages->all() as $message) { |
||
| 84 | $this->error($message); |
||
| 85 | } |
||
| 86 | } else { |
||
| 87 | // create the user |
||
| 88 | $user = $this->user->create([ |
||
| 89 | 'name' => $name, |
||
| 90 | 'email' => $email, |
||
| 91 | 'token' => $this->userRepository->createToken(), |
||
| 92 | 'password' => bcrypt($password), |
||
| 93 | 'active' => 1, |
||
| 94 | ]); |
||
| 95 | // add role |
||
| 96 | $user->assignRole('super-admin'); |
||
| 97 | $this->info('. .'); |
||
| 98 | $this->info('.. ..'); |
||
| 99 | $this->info('... ...'); |
||
| 100 | $this->info('.... AWESOME ....'); |
||
| 101 | $this->info('... ...'); |
||
| 102 | $this->info('.. ..'); |
||
| 103 | $this->info('. .'); |
||
| 104 | $this->info('. .'); |
||
| 105 | $this->info('.. ..'); |
||
| 106 | $this->info('... ...'); |
||
| 107 | $this->info('.... JOB ....'); |
||
| 108 | $this->info('... ...'); |
||
| 109 | $this->info('.. ..'); |
||
| 110 | $this->info('. .'); |
||
| 111 | $this->info(' '); |
||
| 112 | $this->info('New super admin: '.$name.' ('.$email.') generated successfully'); |
||
| 113 | $this->info(' '); |
||
| 114 | } |
||
| 117 |