How to check unused variables / functions in a class

I have a large PHP class with a large variable / function declaration, and I would like to say if all variables / functions are used in the script. Is there something that does this?

+5
source share
3 answers

The dynamic nature of the PHP language (eval, using variables / functions through strings, etc.) makes it theoretically impossible to programmatically determine whether a function or variable is used in any situation.

Manual code analysis is, unfortunately, the best choice.

+2
source

PHP Messager PHP Mess Detector :

<?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>
+8

You can use code coverage tools like PHP_CodeCoverage , which is based on Xdebug , or module testing software like PHPUnit or SimpleTest (with code coverage enabled).

First you need to write a lot of unit tests before you can check the code coverage.

+4
source

All Articles