php - 如何在 PHP 项目中找到未使用的函数

标签 php

如何找到 PHP 项目中未使用的函数?

是否有内置于 PHP 中的功能或 API 允许我分析我的代码库 - 例如 Reflection , token_get_all()

这些 API 的功能是否足以让我不必依赖第三方工具来执行此类分析?

最佳答案

您可以尝试 Sebastian Bergmann 的死代码检测器:

phpdcd is a Dead Code Detector (DCD) for PHP code. It scans a PHP project for all declared functions and methods and reports those as being "dead code" that are not called at least once.

来源:https://github.com/sebastianbergmann/phpdcd

请注意,它是一个静态代码分析器,因此它可能会对仅动态调用的方法给出误报,例如它无法检测到 $foo = 'fn'; $foo();

您可以通过 PEAR 安装它:

pear install phpunit/phpdcd-beta

之后您可以使用以下选项:

Usage: phpdcd [switches] <directory|file> ...

--recursive Report code as dead if it is only called by dead code.

--exclude <dir> Exclude <dir> from code analysis.
--suffixes <suffix> A comma-separated list of file suffixes to check.

--help Prints this usage information.
--version Prints the version and exits.

--verbose Print progress bar.

更多工具:


注意:根据存储库通知,不再维护此项目,其存储库仅用于存档目的。所以你的里程可能会有所不同。

关于php - 如何在 PHP 项目中找到未使用的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2946598/

相关文章:

php - Pyrocms 2.2 升级数据库错误号 : 1054

php - 在数据库中存储树数据结构

php - Laravel sqlite 数据库连接错误

php - Paypal 自适应支付和送货地址

javascript - 无法从本地主机中的 php 文件获取 json 数据

php - RecursiveDirectoryIterator() 不显示空目录

php - 未捕获的 PDOException 泄露用户名和密码

php - 单例适用于我的网站吗

php - 网站MySQL审核系统

php - 根据mysql查询计数 Bootstrap 多行