cleaned up the code example

- added final return for `vote()` function
- moved `$user` below attribute check. if attribute fails, we don't need user
- used already declared constants in switch statement, rather than harcoded strings
bug #4139 cleaned up the code example (gondo)

This PR was submitted for the 2.5 branch but it was merged into the 2.3 branch instead (closes #4139).

Discussion
----------

cleaned up the code example

- added final return for `vote()` function
- moved `$user` below attribute check. if attribute fails, we don't need user
- used already declared constants in switch statement, rather than harcoded strings

Commits
-------

081b3c7 cleaned up the code example