3

Is there any way to scan a codebase for any TODO's and generate a list that can be displayed on a standard web page.

E.g.

@todo Deprecated function remove......... (functions.php [Line 12])

This needs to work on a local WAMP server.

alex
  • 479,566
  • 201
  • 878
  • 984
James Bell
  • 604
  • 1
  • 7
  • 18

3 Answers3

8

On a Windows platform or if you wanted to use PHP itself, you could use...

function getTodos($path) {
   $todos = array();
   $items = glob(rtrim($path, '/') . '/*');

   foreach($items as $item) {

       if (is_file($item) AND pathinfo($item, PATHINFO_EXTENSION) == 'php') {
           $fileContents = file_get_contents($item);

           $tokens = token_get_all($fileContents);

           foreach($tokens as $type = $token) {
               if (($type == 'T_COMMENT' OR $type == 'T_ML_COMMENT')
                   AND preg_match_all('/^\s*(?P<todo>@todo.*?)\z/m', $token, $matches) {
                  $todos = array_merge($todos, $matches['todo']);
               }
           }

       } else if (is_dir($item)) {
           $todos = array_merge$($todos, getTodos($item));
           continue;
       }       

   }

   return $lines;
}

I have not tested it, but it should work in theory. :)

On *nix, you could use grep...

$ grep -r \b@todo\b ./

It's not perfect (it will find it within strings) but it should be good enough. :)

alex
  • 479,566
  • 201
  • 878
  • 984
4

Phpdoc can generate html files from the comments and methods in your codebase. It will also show todos etc.

http://www.phpdoc.org/

red
  • 1,980
  • 1
  • 15
  • 26
1

PHPStorm has an ability to pull up all the todo files, I use it before making commits very nice function and works out of the box.

Its Free for open source Licences, http://www.jetbrains.com/phpstorm/

there are various other licences available http://www.jetbrains.com/phpstorm/buy/index.jsp

[I am not affiliated with Jetbrains just a developer that likes to use it]

Sean
  • 95
  • 1
  • 8