| Conditions | 10 |
| Paths | 576 |
| Total Lines | 24 |
| Code Lines | 16 |
| 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 |
||
| 67 | public function handle() |
||
| 68 | { |
||
| 69 | $data['name_first'] = is_null($this->option('firstname')) ? $this->ask('First Name') : $this->option('firstname'); |
||
| 70 | $data['name_last'] = is_null($this->option('lastname')) ? $this->ask('Last Name') : $this->option('lastname'); |
||
| 71 | $data['username'] = is_null($this->option('username')) ? $this->ask('Username') : $this->option('username'); |
||
| 72 | $data['email'] = is_null($this->option('email')) ? $this->ask('Email') : $this->option('email'); |
||
| 73 | $data['password'] = is_null($this->option('password')) ? $this->secret('Password') : $this->option('password'); |
||
| 74 | $password_confirmation = is_null($this->option('password')) ? $this->secret('Confirm Password') : $this->option('password'); |
||
| 75 | |||
| 76 | if ($data['password'] !== $password_confirmation) { |
||
| 77 | return $this->error('The passwords provided did not match!'); |
||
| 78 | } |
||
| 79 | |||
| 80 | $data['root_admin'] = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin'); |
||
| 81 | |||
| 82 | try { |
||
| 83 | $user = new UserRepository; |
||
| 84 | $user->create($data); |
||
| 85 | |||
| 86 | return $this->info('User successfully created.'); |
||
| 87 | } catch (\Exception $ex) { |
||
| 88 | return $this->error($ex->getMessage()); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.