| Conditions | 16 |
| Paths | 44 |
| Total Lines | 73 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 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 |
||
| 20 | public function __invoke(array $post) { |
||
| 21 | |||
| 22 | # Declare variables |
||
| 23 | |||
| 24 | $name = ''; $email = ''; $rank = ''; $first_name = ''; $last_name = ''; $sex = ''; |
||
| 25 | |||
| 26 | $city = ''; $country = ''; $timezone = ''; $password = ''; $password_retype = ''; |
||
| 27 | |||
| 28 | # Extract post array |
||
| 29 | |||
| 30 | extract($post); |
||
| 31 | |||
| 32 | # Validate name & email |
||
| 33 | |||
| 34 | if (false === ($name = Auth\Validate::userName($name))) return 'USER_ERROR_NAME_INVALID'; |
||
| 35 | |||
| 36 | if (false === ($email = Validate::email($email))) return 'USER_ERROR_EMAIL_INVALID'; |
||
| 37 | |||
| 38 | # Validate password |
||
| 39 | |||
| 40 | if ((0 === $this->user->id) || ('' !== $password)) { |
||
|
|
|||
| 41 | |||
| 42 | if (false === ($password = Auth\Validate::userPassword($password))) return 'USER_ERROR_PASSWORD_INVALID'; |
||
| 43 | |||
| 44 | if (0 !== strcmp($password, $password_retype)) return 'USER_ERROR_PASSWORD_MISMATCH'; |
||
| 45 | } |
||
| 46 | |||
| 47 | # Check name exists |
||
| 48 | |||
| 49 | if (false === ($check_name = $this->user->check('name', $name))) return 'USER_ERROR_MODIFY'; |
||
| 50 | |||
| 51 | if ($check_name === 1) return 'USER_ERROR_NAME_DUPLICATE'; |
||
| 52 | |||
| 53 | # Check email exists |
||
| 54 | |||
| 55 | if (false === ($check_email = $this->user->check('email', $email))) return 'USER_ERROR_MODIFY'; |
||
| 56 | |||
| 57 | if ($check_email === 1) return 'USER_ERROR_EMAIL_DUPLICATE'; |
||
| 58 | |||
| 59 | # Modify user |
||
| 60 | |||
| 61 | $data = []; |
||
| 62 | |||
| 63 | $data['name'] = $name; |
||
| 64 | $data['email'] = $email; |
||
| 65 | $data['rank'] = $rank; |
||
| 66 | $data['first_name'] = $first_name; |
||
| 67 | $data['last_name'] = $last_name; |
||
| 68 | $data['sex'] = $sex; |
||
| 69 | $data['city'] = $city; |
||
| 70 | $data['country'] = $country; |
||
| 71 | $data['timezone'] = $timezone; |
||
| 72 | |||
| 73 | if ((0 === $this->user->id) || ('' !== $password)) { |
||
| 74 | |||
| 75 | $data['auth_key'] = ($auth_key = Str::random(40)); |
||
| 76 | $data['password'] = Str::encode($auth_key, $password); |
||
| 77 | } |
||
| 78 | |||
| 79 | if (0 === $this->user->id) { |
||
| 80 | |||
| 81 | $data['time_registered'] = REQUEST_TIME; |
||
| 82 | $data['time_logged'] = REQUEST_TIME; |
||
| 83 | } |
||
| 84 | |||
| 85 | $modifier = ((0 === $this->user->id) ? 'create' : 'edit'); |
||
| 86 | |||
| 87 | if (!$this->user->$modifier($data)) return 'USER_ERROR_MODIFY'; |
||
| 88 | |||
| 89 | # ------------------------ |
||
| 90 | |||
| 91 | return true; |
||
| 92 | } |
||
| 93 | } |
||
| 95 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.