sebastian/phpdcd - Packagist (original) (raw)

This package is abandoned and no longer maintained. No replacement package was suggested.

Dead Code Detector (DCD) for PHP code.


README

This project is no longer maintained and its repository is only kept for archival purposes.

Latest Stable Version Build Status

PHP Dead Code Detector (PHPDCD)

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.

Limitations

As PHP is a very dynamic programming language, the static analysis performed by phpdcd does not recognize function or method calls that are performed using one of the following language features:

Also note that infering the type of a variable is limited to type-hinted arguments (function foo(Bar <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>b</mi><mi>a</mi><mi>r</mi><mo stretchy="false">)</mo><mrow></mrow><mi mathvariant="normal">‘</mi><mo stretchy="false">)</mo><mi>a</mi><mi>n</mi><mi>d</mi><mi>d</mi><mi>i</mi><mi>r</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>o</mi><mi>b</mi><mi>j</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>c</mi><mi>r</mi><mi>e</mi><mi>a</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo stretchy="false">(</mo><mi mathvariant="normal">‘</mi></mrow><annotation encoding="application/x-tex">bar) {}) and direct object creation (</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">ba</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mclose">)</span><span class="mord"></span><span class="mord">‘</span><span class="mclose">)</span><span class="mord mathnormal">an</span><span class="mord mathnormal">dd</span><span class="mord mathnormal">i</span><span class="mord mathnormal">rec</span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.05724em;">bj</span><span class="mord mathnormal">ec</span><span class="mord mathnormal">t</span><span class="mord mathnormal">cre</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mopen">(</span><span class="mord">‘</span></span></span></span>object = new Clazz)

Installation

PHP Archive (PHAR)

The easiest way to obtain PHPDCD is to download a PHP Archive (PHAR) that has all required dependencies of PHPDCD bundled in a single file:

wget https://phar.phpunit.de/phpdcd.phar
chmod +x phpdcd.phar
mv phpdcd.phar /usr/local/bin/phpdcd

You can also immediately use the PHAR after you have downloaded it, of course:

wget https://phar.phpunit.de/phpdcd.phar
php phpdcd.phar

Composer

Simply add a dependency on sebastian/phpdcd to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPDCD:

{
    "require-dev": {
        "sebastian/phpdcd": "*"
    }
}

For a system-wide installation via Composer, you can run:

composer global require 'sebastian/phpdcd=*'

Make sure you have ~/.composer/vendor/bin/ in your path.