加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何扫描项目中的“@todo”源代码注释

发布时间:2020-12-13 22:02:25 所属栏目:PHP教程 来源:网络整理
导读:有没有办法扫描任何TODO的代码库,并生成可以在标准网页上显示的列表. 例如. @todo Deprecated function remove……… (functions.php [Line 12]) 这需要在本地WAMP服务器上运行. 解决方法 在 Windows平台上或者如果您想使用 PHP本身,您可以使用… function g
有没有办法扫描任何TODO的代码库,并生成可以在标准网页上显示的列表.

例如.

@todo Deprecated function remove……… (functions.php [Line 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;
}

我没有测试它,但它应该在理论上工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读