How do I customize NetBeans PHP auto DocBlock for methods and attributes?
Asked Answered
S

4

34

After I create a method I use /**<enter> to generate the DocBlock. It auto fills the @param and @return for that function. Example:

/**
 *
 * @param type $str
 * @return type 
 */
public function strlen($str){
    return strlen($str);
}

How can I customize the block being generated so that it also fills in the @author and end up with this after /**<enter>

/**
 *
 * @param type $str
 * @return type 
 * @author John Doe <[email protected]>
 */
public function strlen($str){
    return strlen($str);
}

Thanks

Saltsman answered 7/5, 2011 at 17:31 Comment(4)
I haven't seen any option for this, nor can you manually add it with Code Templates as they won't work within comments. I'd be interested to find out if there's any way to do this.Seton
I have no idea, BUT you could, in the mean time, use macros to do it. I have @copyright and @author macros when docblocking classes. I'd also suggest @author'ing the class, rather than each individual method.Bieber
@Shadower856 I hadn't even noticed the macros capabilities in 2 years of using netbeans! I've been using Code Templates but those won't work outside of code areas.. great tipSeton
@Bieber does this also work with dynamic content, like inserting the current date using an template like @today?Tableau
F
5

There may be a better way to do this, but here's what I've used: under Tools > Options > Editor > Code Templates, there are some predefined combos for generating code quickly. One of the default templates in 7.0 is:

vdoc<tab>

This generates a pseudo-docblock and the variable definition. You can replace this and add new ones that expand into whatever text you want, much like vim abbreviations. You can find more on this on the Netbeans documentation site:

http://netbeans.org/kb/docs/php/code-templates.html#using-templates

Flaky answered 2/8, 2011 at 16:10 Comment(0)
P
4

I believe the answer you're looking for will be found here: phpDocumentor Tutorial

I think you'll want to look at the --customtags Command-line switch.

So most likely, when you go to Tools -> Options -> "PHP" -> "PHPDoc", you can add that --customtags command-line switch into the PHPDoc script line.

I haven't attempted this personally, but I have been playing around with the idea of using NetBeans in combination with DocBlocks and PHPDocumentor to "automagically" create a good amount of usable documentation without being too strenuous on the rest of the coders. ;-)

There's a nice video tutorial about setting up NetBeans to work with PHPDocumentor available here: Generating PHP Documentation With NetBeans IDE 7.0

Prothalamion answered 11/8, 2011 at 18:21 Comment(0)
L
3

To enable proper @author tag autocompletion, just go to: Tools->Templates->PHP->PHP Class, press the "Settings" button and uncomment the line starting with #user=. Now you're able to edit the name and email, which are passed to your Class comment.

Leash answered 7/7, 2014 at 10:15 Comment(1)
This works for the class which is useful, but doesn't work for the function doc blocks which is what the OP is asking forMoffatt
S
0

Short Answer from various sources: No you can't edit a template that could add it for you.

  1. If you are still looking for a feature alike, you can create a Macro do to it and then bind it to a shortcut ("Alt + W" for instance).

To create a Macro : Tools -> Options -> Editor -> Macros

Example :

Alt+W => insert-break "/**" insert-break

This Macro helps add PHPDoc with the left hand which makes it faster. You can generate whatever you wish to generate like using this Macro, and then placing the cursor at the right place and then adding the @author YOUR_NAME at the end of the comment.


  1. You can also set the general Author of your project by going to : Tools -> Templates; Click "Settings"

Add the line :

user=YOUR NAME <email.prefix at domain.extension>

This will add the @author to all your new class/interface definitions.

I hope this will help you!

Steak answered 21/8, 2017 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.