Dead Code Detector (DCD) for PHP code.

Related tags

Miscellaneous phpdcd
Overview

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:

  • Reflection API
  • call_user_func() and call_user_func_array()
  • Usage of the new operator with variable class names
  • Variable class names for static method calls such as $class::method()
  • Variable function or method names such as $function() or $object->$method()
  • Automatic calls to methods such as __toString() or Iterator::*()

Also note that infering the type of a variable is limited to type-hinted arguments (function foo(Bar $bar) {}) and direct object creation ($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.

Comments
  • (Re)introduce progress bar

    (Re)introduce progress bar

    A progress bar was originally implemented with ezcConsoleProgressbar, but this was removed by commit 31d5d775f8bedb6a189ed8289047c3d87b04e7e4

    This commit re-introduces a progress bar using Symfony\Component\Console\Helper\ProgressHelper

    opened by soxofaan 2
  • Load Symfony Finder's autoloader.php instead of brittle hardcoded requires

    Load Symfony Finder's autoloader.php instead of brittle hardcoded requires

    When trying out the latest version of phpdcd I had Symfony autoloader issues: PHPDCD/Autoload.php uses explicit includes of symfony classes, without the symfony autoloader loaded at that point, which caused include dependency hell. Just loading Symfony/Component/Finder/autoloader.php fixed the issue for me

    opened by soxofaan 2
  • fixes for Symfony autoload issue and undefined variable issue

    fixes for Symfony autoload issue and undefined variable issue

    9ab7becb380e58a929089e3898e8ef7f52d2006b When trying out the latest version of phpdcd I had Symfony autoloader issues: PHPDCD/Autoload.php uses explicit includes of symfony classes, without the symfony autoloader loaded at that point, which caused include dependency hell. Just loading Symfony/Component/Finder/autoloader.php fixed the issue for me

    34757babcc1d58edf8fd0061e858c2261aa7e859 other issue: I got "Undefined variable: commonPath" notices

    opened by soxofaan 1
  • Issue 24: parent double colon handling

    Issue 24: parent double colon handling

    two commits:

    • fix for issue #24
    • follow up commit to avoid endless loop on illegal class hierarchy cycles

    feel free to consider the last commit as too exotic

    opened by soxofaan 0
  • Issue 18: support for parent methods

    Issue 18: support for parent methods

    This pull request fixes issue #18: functions defined in parent classes can now be detected as used

    The pull request consist of two commits:

    A first one to split up code parsing and dead code detection logic (in separate classes: Analyser and Detector). There is no functional change here, it only makes it easier and cleaner to fix issue18 (and allow future improvements)

    A second commit to actually fix issue 18

    I hope that splitting this up in two commits makes review also easier

    opened by soxofaan 0
Owner
Sebastian Bergmann
Sebastian Bergmann is the creator of PHPUnit. He co-founded thePHP.cc and helps PHP teams build better software.
Sebastian Bergmann
PHP Magic Number Detector

PHP Magic Number Detector (PHPMND) phpmnd is a tool that aims to help you to detect magic numbers in your PHP code. By default 0 and 1 are not conside

Povilas Susinskas 514 Dec 14, 2022
Magento Project Mess Detector

Magento Project Mess Detector Author: Fabrizio Branca (fbrnc.net / @fbrnc) Some additional commands for the excellent n98-magerun Magento command-line

AOE 181 Aug 3, 2022
Result of our code-along meetup writing PHP 8.1 code

PHP 8.1 Demo Code This code demonstrates various PHP 8.0 and 8.1 features in a realistic, functional (but incomplete) codebase. The code is part of so

azPHP 2 Nov 14, 2021
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

⚗️ About Larastan Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural, Nuno Maduro, and Vik

Nuno Maduro 4.4k Jan 4, 2023
Free ZIP Code API - Free Access to Worldwide Postal Code Data

About Zipcodebase - Free Zip Code API Zipcodebase is a zip code API that was founded in 2019 to solve common issues with postal code data. As we have

SaaS Industries 2 Nov 26, 2022
Preload your sweet sweet code to opcache with a composer command, making your code faster to run.

Composer Preload Preload your sweet sweet code to opcache with a composer command, making your code run faster. Composer Preload is a composer plugin

Ayesh Karunaratne 197 Dec 6, 2022
The SensioLabs DeprecationDetector runs a static code analysis against your project's source code to find usages of deprecated methods, classes and interfaces

SensioLabs DeprecationDetector CAUTION: This package is abandoned and will no longer receive any updates. The SensioLabs DeprecationDetector runs a st

QOSSMIC GmbH 389 Nov 24, 2022
Webman quickly creates a verification code tool similar to Google verification code

webman-captcha-grid webman quickly creates a verification code tool similar to Google verification code webman 快速创建一个类似于 Google 点图验证码的本地验证码扩展 介绍 webma

听风吹雨 6 Dec 5, 2022
Code to accompany the YouTube video "Full PHP cURL API tutorial - how to use a REST API from PHP using cURL"

PHP cURL CRUD Example Example code to accompany this YouTube video. Note that the init_curl.php file contains a placeholder for an API key. DO NOT che

Dave Hollingworth 14 Dec 24, 2022
The VarExporter component allows exporting any serializable PHP data structure to plain PHP code.

The VarExporter component allows exporting any serializable PHP data structure to plain PHP code. While doing so, it preserves all the semantics associated with the serialization mechanism of PHP (__wakeup, __sleep, Serializable).

Symfony 1.8k Jan 1, 2023
A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Felix Becker 1.1k Jan 4, 2023
Clean Code concepts adapted for PHP - A guide for producing readable, reusable, and refactorable PHP software

Clean Code concepts adapted for PHP - A guide for producing readable, reusable, and refactorable PHP software

Fabio Soares 172 Dec 25, 2022
Check modules in app/code and vendor for PHP 8 compatibility status - PHP_CodeSniffer & php-compatibility standard

M2 PHP version compatibility check How To use Requires PHP 7.3+ | PHP 8 This app will run PHP_CodeSniffer with phpcompatibility/php-compatibility on t

William Tran 24 Oct 13, 2022
Opens an interactive PHP console for running and testing PHP code.

wp-cli/shell-command Opens an interactive PHP console for running and testing PHP code. Quick links: Using | Installing | Contributing | Support Using

WP-CLI 20 Nov 4, 2022
Lock library to provide serialized execution of PHP code.

Requirements | Installation | Usage | License and authors | Donations php-lock/lock This library helps executing critical code in concurrent situation

null 875 Jan 7, 2023
🔨 Prefixes all PHP namespaces in a file/directory to isolate the code bundled in PHARs.

PHP-Scoper PHP-Scoper is a tool which essentially moves any body of code, including all dependencies such as vendor directories, to a new and distinct

Humbug 590 Jan 2, 2023
Easily create and work with code snippets from PHP

code-snippets Easily create and work with code snippets from source code files of any type in PHP. The original code this package is based on was borr

Permafrost Software 8 Sep 4, 2022
A minimal library that defines primitive building blocks of PHP code.

Jungi Common A minimal library that defines primitive building blocks of PHP code. It combines the advantages of functional and object-oriented progra

Piotr Kugla 28 Jul 15, 2022