Welcome Guest, Not a member yet? Register   Sign In
How to use phpdoc correctly in this case
#1

[eluser]Slowcheetah[/eluser]
The model below gets 2 input parameters, 1 string (id) and 1 array (account_data) and returns a bool (true or false). Is this the most efficient method, and is my phpdoc header formatted correctly?

Code:
/**
     * function update_profile($id, $account_data)
     *
     * Updates profile database
     * @version 0.1
     * @param $id - string, $account_data - array
     * @return Bool - TRUE or FALSE
     */
    
    function update_profile($id, $account_data) {
        $this->db->where('id', $id);
        $this->db->update('profiles', $account_data);
        
        if ($this->db->affected_rows() == '1') {
            return TRUE;
        }
        
        return FALSE;
    }
#2

[eluser]Dam1an[/eluser]
This is how I would do it
Code:
/**
* Update the users profile
* An optional longer description goes here
*
* @param String $id - The ID of the user to update
* @param Array $account_data - Any data to update for the user
* @return Boolean - Returns true on success and false otherwise
*/

I don't bother with the method signature as you did, as I get this from the auto complete within my IDE
I also don't put the version number for each function doc block, but I just put it in the class doc block (some people like to put the @since tag for the function)
I prefer to put each parameter on a seperate line and decalre the type bfore the variable
And finally with the return, I just specify the type and in what scenario you get which

At the end of the day, it's mainly a matter of peronal preference, so just do whatever works for you Smile
#3

[eluser]Slowcheetah[/eluser]
Thanks for answering, wich IDE you use to autocomplete the phpdoc? I use Aptana Studio, but i cant seem to find the autocomplete function.
#4

[eluser]Dam1an[/eluser]
I use Eclipse which is what Aptana is based on.
Auto complete is normally Ctrl + space, but with comments, if you just type /** and hit enter on the line above a function, it should do it for you?

In Eclipse, the comment templates are defined in Windows > Preferences > PHP > Code Style > Templates and then select comments (that is assuming Aptana didn;t change too much)




Theme © iAndrew 2016 - Forum software by © MyBB