• 分析和解析PHP代码的7大工具


    介绍几个非常不错的工具,来帮助程序员们提高自己的工作效率,一起来看看吧!

    1  PHP Parser  : https://github.com/nikic/PHP-Parser

       PHP-Parser是一个用PHP编写的PHP解析器(支持PHP 5.4以及更早的版本),这种特殊的解析器非常适合静态代码分析。该工具的目的就是简化静态代码分析和操作,它使程序员能够以编程的方式来处理任何应用程序的代码。

    2 PHPSandbox : https://github.com/fieryprophet/php-sandbox

       PHPSandbox将运行PHP作为独立进程的一种方式。 它为程序员提供一种外围脚本的保护,比如错误、崩溃、运行慢的脚本,或者不适合在代码中运行的脚本,都可作为独立进程来运行。

    3  PHP Mess Detector : https://phpmd.org/

      PHPMD这个工具能够探测PHP源代码中一些潜在的问题。例如:

    • 可能存在的Bug
    • 未达最佳标准的代码
    • 过于复杂的语法
    • 从未使用过的参数、方法、属性

    4 PHPCPD : https://github.com/sebastianbergmann/phpcpd

      PHPCPD是一个在代码中寻找类似模式的工具,使用它是为了在代码库中识别代码在何处被复制或粘贴。这是常规构建过程中一个非常有用的工具,它会帮助程序员分析代码,以避免在代码库中重复调用函数。

     

    5  PHPCheckstyle : https://phpcheckstyle.github.io/

      PHPCheckstyle是一个帮助PHP程序员检查代码和报告错误的工具,运行于PHP 5.0以及更高的版本。通过SVN钩子脚本的方式来调用PHPCheckstyle,可以强制代码必须符合预先设定的编码标准(比如PEAR编码标准),有助于在多人合作项目中提高代码整体质量。

    6 Ubench : https://github.com/devster/ubench

    Ubench是一个用于评测PHP代码执行时间和内存使用效率的开发库。使用方法如下:

    require_once 'src/Ubench.<span id="1_nwp" style=" auto; height: auto; float: none;"><a id="1_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=18&is_app=0&jk=52d10cc8a331984b&k=php&k0=php&kdi0=0&luki=8&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=4b9831a3c80cd152&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F6257%2Ehtml&urlid=0" target="_blank" mpid="1" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;auto;height:auto;float:none;">php</span></a></span>';
    $bench = new Ubench;
    $bench->start();
    // Execute some code
    $bench->end();
    // Get elapsed time and <span id="2_nwp" style=" auto; height: auto; float: none;"><a id="2_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=18&is_app=0&jk=52d10cc8a331984b&k=memory&k0=memory&kdi0=0&luki=4&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=4b9831a3c80cd152&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F6257%2Ehtml&urlid=0" target="_blank" mpid="2" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;auto;height:auto;float:none;">memory</span></a></span>
    echo $bench->getTime(); // 156ms or 1.123s
    echo $bench->getTime(true); // elapsed microtime in float
    echo $bench->getTime(false, '%d%s'); // 156ms or 1s
    echo $bench->getMemoryPeak(); // 152B or 90.00Kb or 15.23Mb
    echo $bench->getMemoryPeak(true); // memory <span id="3_nwp" style=" auto; height: auto; float: none;"><a id="3_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=18&is_app=0&jk=52d10cc8a331984b&k=peak&k0=peak&kdi0=0&luki=3&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=4b9831a3c80cd152&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F6257%2Ehtml&urlid=0" target="_blank" mpid="3" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;auto;height:auto;float:none;">peak</span></a></span> in bytes
    echo $bench->getMemoryPeak(false, '%.3f%s'); // 152B or 90.152Kb or 15.234Mb
    // Returns the memory usage at the end <span id="4_nwp" style=" auto; height: auto; float: none;"><a id="4_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=18&is_app=0&jk=52d10cc8a331984b&k=mark&k0=mark&kdi0=0&luki=2&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=4b9831a3c80cd152&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F6257%2Ehtml&urlid=0" target="_blank" mpid="4" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;auto;height:auto;float:none;">mark</span></a></span>
    echo $bench->getMemoryUsage(); // 152B or 90.00Kb or 15.23Mb

     

     7 PHP Analyzer : https://scrutinizer-ci.com/docs/tools/php/php-analyzer/

     PHP Analyzer执行和编译器相同的流动分析,确保代码在每个潜在执行路径的每一行都执行了测试。这种特殊的工具帮助开发人员提高了自己的代码质量,从而确保了工作效率。

     

  • 相关阅读:
    设计模式:Prototype 原型模式
    [C++STDlib基础]关于单字符的操作——C++标准库头文件<cctype>
    Android开发之简单的电子相册实现
    autotools入门笔记(二)——创建和使用静态库、动态库
    Dreamer 框架 比Struts2 更加灵活
    Redis集群明细文档
    【Servlet3.0新特性】第03节_文件上传
    POJ 3264 Balanced Lineup
    利用jquery对ajax操作,详解原理(附代码)
    C语言实现修改文本文件中的特定行
  • 原文地址:https://www.cnblogs.com/richerdyoung/p/10071717.html
Copyright © 2020-2023  润新知