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/11532/

相关文章:

php - 为什么libcurl会计算 "4 TIMES"添加easy handles的个数?

php - 通过 'for' 循环插入 MySQL 表,并在字符串之间使用变量

php - PHP require 和 include 有什么区别?

javascript - 加载脚本时有时会收到解析错误

php - 编写 PHP 脚本将 JSON 转换为 PHP 数组并存储在 MySQL 中

php - 忽略 Assets lessphpfilter中的.css文件

php - PHP MYSQL Select 语句帮助

javascript - Vue 的多个模态组件

php - 如何在 wordpress 主题/插件中将状态标题设置为 200

php - 如何在 Azure 应用程序服务 -> Web 应用程序 (Linux) 中启用 php 扩展