代码之家  ›  专栏  ›  技术社区  ›  ae.

有没有一个PHP重构工具可以告诉哪些函数从来没有被调用过?[复制]

  •  4
  • ae.  · 技术社区  · 15 年前

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

    PHP中是否有一些特性或API可以让我分析我的代码库-例如 Reflection , token_get_all() ?

    这些api的特性是否足够丰富,使我不必依赖第三方工具来执行这种类型的分析?

    0 回复  |  直到 8 年前
        1
  •  2
  •   Sandy Garrido    4 年前

    你可以试试塞巴斯蒂安·伯格曼的死码探测器:

    phpdcd 是PHP代码的死代码检测器(DCD)。它扫描PHP项目中所有声明的函数和方法,并将这些函数和方法报告为“死代码”,至少没有调用一次。

    https://github.com/sebastianbergmann/phpdcd

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

    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.
    

    更多工具:


    注: 根据仓库通知, 此项目不再维护,其存储库仅用于存档目的

    推荐文章