Freedom251 › Code Duplication Detection Tools
phpcpd-next

What phpcpd-next 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. By default, it combines Rabin-Karp exact matching with TokenBag detection for reordered code. An optional unified engine looks for exact, renamed, gapped, and reordered clones, while optional orphan detection identifies unreferenced classes, interfaces, traits, enums, and functions. Reports can be produced in the console, PMD-CPD XML, JSON, or SARIF 2.1.0. For CI, 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 are Composer as a development dependency or global package, and source. It requires PHP 8.4 or later, ext-dom, and ext-mbstring, with zero Composer runtime dependencies. The project describes advanced engines as research-grade and says they can produce more false positives than the default detection set.
Who it suits
It suits PHP developers who want repository-level clone detection in CI or through documented PHPUnit and GitHub Code Scanning integrations. Users need PHP 8.4 or later and the required extensions.
What it does well
- Free and MIT licensed
- Provides console, XML, JSON, and SARIF output
- CI support includes caching and an incremental index
- Zero Composer runtime dependencies
What to know first
- Requires PHP 8.4 or later
- Requires ext-dom and ext-mbstring
- Advanced engines may produce more false positives
Limits
The free, MIT-licensed plan requires PHP 8.4 or later, ext-dom, and ext-mbstring. Optional advanced engines are described as research-grade and may produce more false positives than the default set.
Plans
| Plan | Billed and limits | Price |
|---|---|---|
| Open source | MIT licensed · requires PHP 8.4+ with ext-dom and ext-mbstring · install via Composer | Free |
As github.com lists them, read 5 Oct 2026. The maker's own page has the final word.
Getting started
- Open the project website on GitHub.
- Install it as a Composer development dependency, a global Composer package, or from source.
- Use PHP 8.4 or later and install ext-dom and ext-mbstring.
- Run it against a PHP repository; enable optional detection modes if needed.
Verdict
phpcpd-next offers several clone-detection modes and output formats, including options for CI workflows. Its advanced engines carry a stated false-positive caveat, and the duplicated-line percentage cannot replace review of structural repetition in code design.
Questions
Is phpcpd-next free?
Yes. The project is open source and MIT licensed.
What does it detect?
Its default run detects exact matches and reordered code. An optional unified engine detects exact, renamed, gapped, and reordered clones, while `--orphans` finds unreferenced declarations.
Which platforms does it support?
It requires PHP 8.4 or later, ext-dom, and ext-mbstring.
Can it be used in CI?
Yes. It supports meaningful exit codes, result caching, and a per-file incremental index. Clone findings return status 1.
How can I install it?
The documented options are installation as a Composer development dependency, as a global Composer package, or from source.
Does it integrate with IDEs?
Documented integration options include PHPUnit, a headless in-process API, framework presets, and SARIF upload to GitHub Code Scanning.
Facts from phpcpd-next's own pages
- CI use
- Meaningful exit codes, result caching, and a per-file incremental index support CI use; clone findings produce exit status 1. · github.com, 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, 5 Oct 2026
- Founded
- 2026 · github.com, 28 Sept 2026
- Integrations
- The project documents PHPUnit integration, an in-process headless API, framework presets, and SARIF upload to GitHub Code Scanning. · github.com, 5 Oct 2026
- License
- The project states that phpcpd-next is licensed under MIT. · github.com, 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, 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, 5 Oct 2026
- Orphan detection
- The optional --orphans mode finds unreferenced classes, interfaces, traits, enums, and functions. · github.com, 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, 5 Oct 2026
- Reports
- It provides console, PMD-CPD XML, JSON, and SARIF 2.1.0 output formats. · github.com, 5 Oct 2026
- Requirements
- It requires PHP 8.4+, ext-dom, and ext-mbstring, and lists zero Composer runtime dependencies. · github.com, 5 Oct 2026
- Setup
- The documented installation is as a Composer development dependency, as a global Composer package, or from source. · github.com, 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, 5 Oct 2026
Where phpcpd-next stands on Freedom251
- Code Duplication Detection Tools#9 of 18
- Code Clone Detection Tools#13 of 23