- Home
- Code Duplication Detection Tools
- phpcpd-next
phpcpd-next
What it is
phpcpd-next is a free, MIT-licensed token-based detector for copied and similar PHP code across a repository. It targets PHP 8.4 and later and is a successor to Sebastian Bergmann’s phpcpd. Its default scan combines Rabin-Karp exact matching with TokenBag detection for reordered code. An opt-in unified engine looks for exact, renamed, gapped, and reordered clones, while optional orphan detection finds unreferenced classes, interfaces, traits, enums, and functions. Results can be produced in the console or as PMD-CPD XML, JSON, or SARIF 2.1.0. For CI workflows, it offers meaningful exit codes, result caching, and a per-file incremental index; clone findings produce exit status 1. Documented integrations include PHPUnit, an in-process headless API, framework presets, and SARIF upload to GitHub Code Scanning. Installation options include a Composer development dependency, a global Composer package, or source. It requires PHP 8.4 or later, ext-dom, and ext-mbstring, with zero Composer runtime dependencies. The project cautions that advanced engines are research-grade and can have more false positives on real-world code.
For and against
For
- Free and MIT licensed.
- Offers console, XML, JSON, and SARIF reports.
- Includes caching and incremental indexing for CI.
- Has optional orphan detection.
- Zero Composer runtime dependencies.
Against
- Requires PHP 8.4 or later.
- Requires ext-dom and ext-mbstring.
- Advanced engines may produce more false positives.
- No IDE integration is listed.
The verdict
phpcpd-next offers several clone-detection modes, report formats, and CI-oriented features at no cost. Its PHP requirements are specific, and the project flags its advanced engines as research-grade.
Who it suits
It suits PHP developers who want repository-wide clone detection and CI reporting. It may be useful to teams working with PHP 8.4 or later and comfortable installing through Composer or from source.
Plans and prices
Open source
MIT licensed · requires PHP 8.4+ with ext-dom and ext-mbstring · install via Composer
Read 5 Oct 2026 · github.com
On the record
- CI use
- Meaningful exit codes, result caching, and a per-file incremental index support CI use; clone findings produce exit status 1.github.com · read 5 Oct 2026
- Detection
- Its default run combines Rabin-Karp exact matching with TokenBag detection of reordered code; an opt-in unified engine detects exact, renamed, gapped, and reordered clones.github.com · read 5 Oct 2026
- Integrations
- The project documents PHPUnit integration, an in-process headless API, framework presets, and SARIF upload to GitHub Code Scanning.github.com · read 5 Oct 2026
- License
- The project states that phpcpd-next is licensed under MIT.github.com · read 5 Oct 2026
- Limit: design repetition
- The README says the duplicated-line percentage measures copied tokens and cannot substitute for reviewing structural repetition in code design.github.com · read 5 Oct 2026
- Limit: research engines
- The README describes advanced engines as opt-in and research-grade, with higher false-positive rates on real-world code than the default set.github.com · read 5 Oct 2026
- Orphan detection
- The optional --orphans mode finds unreferenced classes, interfaces, traits, enums, and functions.github.com · read 5 Oct 2026
- Purpose
- phpcpd-next is a token-based copy/paste detector for PHP 8.4+ and a successor to Sebastian Bergmann’s phpcpd.github.com · read 5 Oct 2026
- Reports
- It provides console, PMD-CPD XML, JSON, and SARIF 2.1.0 output formats.github.com · read 5 Oct 2026
- Requirements
- It requires PHP 8.4+, ext-dom, and ext-mbstring, and lists zero Composer runtime dependencies.github.com · read 5 Oct 2026
- Setup
- The documented installation is as a Composer development dependency, as a global Composer package, or from source.github.com · read 5 Oct 2026
- Support
- The opened project page describes contribution guidance and a Contributor License Agreement; it does not state a paid support plan.github.com · read 5 Oct 2026