I recently created a CMS for the client which is meant to work out of the box. But I made a mistake by not commenting my code at the time of writing. Just wanted to know if there is a tool that will go through the files of CMS and add comment blocks automatically.

Let's suppose I have this code:

class foo{
  function bar(array $array){
    print_r ($array);

The tool should be able to comment it like (or somewhat similar):

class foo{

 * bar
 * @access  public
 * @param   array
 * @return  void
 function bar(array $array){
  print_r ($array);



The tool should only add phpdoc stubs, i will write explanatory comments myself.


As PHP doesn't support type-hinting (only array and classes, no scalar types, even 5.4 doesn't implement it afaik) it'll be hard to do this, wouldn't it? Furthermore, as PHP isn't strongly typed and as you can use stuff like dynamic variable names it'll be real hard to determine the return type.

Written by NikiC

@nikic: Yeah that is just an example as i expected that and said in my question or somewhat similar :)

Written by Sarfraz

Similar to previous question stackoverflow.com/questions/1232380/… but no useful answers there I'm afraid

Written by Mark Baker

Accepted Answer

While I am sure there is tools that can reflect on the signature (and to a lesser extent tokenize the method body), I am pretty sure there is no tool that would be able to insert the short or long description of the method. Think about it, that's where you - the developer - describes what the function is supposed to do.

So even if there is a tool that can insert the stubs, you will have to go through each comment anyway. And in this case, you can just as well use an IDE like Zend Studio, Eclipse with PDT or Netbeans to insert the comment blocks. They will insert the stubs when opening a new comment block automatically, so all you have to do is fill in the description.

Written by Gordon
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki