LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

phpcpd

finds duplicate code in PHP projects

TLDR

Find duplicate code
$ phpcpd [src/]
copy
Set minimum lines
$ phpcpd --min-lines [10] [src/]
copy
Set minimum tokens
$ phpcpd --min-tokens [50] [src/]
copy
Exclude directory
$ phpcpd --exclude [vendor] [src/]
copy
Output to file
$ phpcpd --log-pmd [report.xml] [src/]
copy
Check multiple directories
$ phpcpd [src/] [lib/]
copy
Fuzzy matching
$ phpcpd --fuzzy [src/]
copy

SYNOPSIS

phpcpd [--min-lines n] [--min-tokens n] [--exclude dir] [options] directories

DESCRIPTION

phpcpd (PHP Copy/Paste Detector) finds duplicate code in PHP projects. It identifies code that should be refactored.Token-based analysis finds similar code blocks. Renaming variables doesn't hide duplications.Thresholds control sensitivity. Higher minimums find larger, more significant duplications.Fuzzy matching finds near-duplicates. Code with minor differences is also detected.Reports show file locations and duplicated content. Integration with CI tools enables automated checks.

PARAMETERS

--min-lines N

Minimum lines for duplication.
--min-tokens N
Minimum tokens for duplication.
--exclude DIR
Exclude directory.
--log-pmd FILE
PMD-CPD XML format.
--fuzzy
Fuzzy matching.
--suffix EXT
File suffix to check.
-v, --verbose
Verbose output.
--help
Show help.

CAVEATS

Similar but intentionally different code may be flagged. Very large codebases may be slow. Note: phpcpd has been archived by its author and is no longer actively maintained. Consider alternative static analysis tools for new projects.

HISTORY

phpcpd was created by Sebastian Bergmann as part of the PHP QA toolset. It helps maintain code quality by detecting copy-pasted code blocks.

SEE ALSO

phpcs(1), phpcbf(1), phpmd(1), phpstan(1)

Copied to clipboard
Kai