开发者

how to check for unused variables/functions in class

I have a large PHP class that has 开发者_运维百科a large variable/function declaration and I wanted to chek if all the variables/functions are being used in the script. Is there something that does this?


You could use PHP Mess Detector PHP Mess Detector with configuration file:

<?xml version="1.0"?>
<ruleset name="My first PHPMD rule set"
     xmlns="http://pmd.sf.net/ruleset/1.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
                 http://pmd.sf.net/ruleset_xml_schema.xsd"
     xsi:noNamespaceSchemaLocation="
                 http://pmd.sf.net/ruleset_xml_schema.xsd">

    <rule ref="rulesets/unusedcode.xml" />
</ruleset>


The dynamic nature of the PHP language (eval, using variables/functions via strings, etc...) makes it theoretically impossible to programmatically determine if a function or variable is ever used in any and all possible situations.

Manual code analysis is, unfortunately, your best bet.


You could use code coverage tools like PHP_CodeCoverage, which is based on Xdebug's statement coverage functionality, or unit testing software like PHPUnit or SimpleTest (which have code coverage integrated).

You'd need to write many unit tests first, before you could test your code coverage, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜