| Conditions | 14 |
| Paths | 14 |
| Total Lines | 32 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 getErrorMessage() |
||
| 59 | { |
||
| 60 | switch ($this->errorCode) { |
||
| 61 | case self::NAME_EMPTY: |
||
| 62 | return 'You\'ve not chosen a username!'; |
||
| 63 | case self::NAME_EXISTS: |
||
| 64 | case self::NAME_EXISTS_SUL: |
||
| 65 | return 'I\'m sorry, but the username you selected is already taken. Please try another. Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore [[User:example]] would become [[User:Example]].'; |
||
|
|
|||
| 66 | case self::NAME_NUMONLY: |
||
| 67 | return 'The username you chose is invalid: it consists entirely of numbers. Please retry with a valid username.'; |
||
| 68 | case self::NAME_INVALIDCHAR: |
||
| 69 | return 'There appears to be an invalid character in your username. Please note that the following characters are not allowed: <code># @ / < > [ ] | { }</code>'; |
||
| 70 | case self::NAME_SANITISED: |
||
| 71 | return 'Your requested username has been automatically adjusted due to technical restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.'; |
||
| 72 | case self::EMAIL_EMPTY: |
||
| 73 | return 'You need to supply an email address.'; |
||
| 74 | case self::EMAIL_WIKIMEDIA: |
||
| 75 | return 'Please provide your email address here.'; |
||
| 76 | case self::EMAIL_INVALID: |
||
| 77 | return 'Invalid E-mail address supplied. Please check you entered it correctly.'; |
||
| 78 | case self::EMAIL_MISMATCH: |
||
| 79 | return 'The email addresses you entered do not match. Please try again.'; |
||
| 80 | case self::OPEN_REQUEST_NAME: |
||
| 81 | return 'There is already an open request with this name in this system.'; |
||
| 82 | case self::BANNED: |
||
| 83 | return 'I\'m sorry, but you are currently banned from requesting accounts using this tool. However, you can still send an email to [email protected] to request an account.'; |
||
| 84 | case self::BANNED_TOR: |
||
| 85 | return 'Tor exit nodes are currently banned from using this tool due to excessive abuse. Please note that Tor is also currently banned from editing Wikipedia.'; |
||
| 86 | } |
||
| 87 | |||
| 88 | throw new Exception('Unknown validation error'); |
||
| 89 | } |
||
| 90 | |||
| 100 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.