有没有办法扫描任何TODO的代码库,并生成可以在标准网页上显示的列表.
例如
@todo不推荐使用的函数删除.........(functions.php [第12行])
这需要在本地WAMP服务器上运行.
在Windows平台上或者如果您想使用PHP本身,您可以使用...
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;
}
Run Code Online (Sandbox Code Playgroud)
我没有测试它,但它应该在理论上工作.:)
在*nix上,你可以使用grep ...
$ grep -r \b@todo\b ./
Run Code Online (Sandbox Code Playgroud)
它并不完美(它会在字符串中找到它)但它应该足够好.:)