- How do I install sbrindle/phpcpd in a Laravel project?
- Install it as a development dependency with composer require --dev sbrindle/phpcpd. Composer places the phpcpd binary in vendor/bin, so you can run vendor/bin/phpcpd app from your project root. Keeping it in require-dev means the tool is never shipped to production.
- Does sbrindle/phpcpd work with Laravel applications?
- Yes. It is a PHP copy/paste detector that scans PHP source files, so it works on any Laravel codebase regardless of your Laravel version. Point it at directories such as app and routes to focus on your own code, and exclude vendor, storage and bootstrap/cache so the report only contains clones you can actually act on.
- How do I exclude vendor, storage and generated files from the scan?
- Use the exclude option and repeat it for each path, for example vendor/bin/phpcpd app --exclude vendor --exclude storage --exclude bootstrap/cache. Excluding third-party and generated code keeps the clone report focused on code your team maintains. You can also store the common flags in a Composer script so every developer runs the same command.
- What does the phpcpd duplicate code report actually show?
- The report lists clone clusters: groups of matching code blocks with the file paths and line ranges of each occurrence. Each cluster shows how many lines and tokens were duplicated, which helps you judge whether it is a genuine refactoring target. You can use the reported locations to jump straight to the files involved in a code review.
- How do I configure the minimum lines and tokens for duplicate detection?
- The detector exposes thresholds for both lines and tokens so small, incidental matches are ignored. Raise the minimum lines or tokens to reduce noise in a large legacy codebase, or lower them for a stricter audit. Start with the defaults, then tune the thresholds once you have seen your first report.
- Can I run sbrindle/phpcpd in a CI pipeline such as GitHub Actions?
- Yes. Because it is a plain Composer binary, you can run it as a step after composer install in any CI runner, including GitHub Actions and GitLab CI. Capture the output in the job log or as an artifact and fail the build when clones above your threshold are reported, so duplication cannot creep in unnoticed.
- Is sbrindle/phpcpd a replacement for PHPStan, Pint or PHP_CodeSniffer?
- No. Those tools handle static analysis, formatting and coding standards, while sbrindle/phpcpd only looks for duplicated code. They complement each other: run the copy/paste detector to find refactoring candidates and keep static analysis and style checks for correctness and consistency.
- How does sbrindle/phpcpd compare to the original phpcpd package?
- It provides the same style of command line copy/paste detection, so existing phpcpd commands and flags should feel familiar. The original phpcpd project is no longer actively developed, making this package a practical option for teams that still want duplication checks. Review the repository's release history before adopting it and pin a version in composer.json.
- How do I add phpcpd as a Composer script for local checks?
- Add an entry to the scripts section of composer.json, mapping a name such as quality:dupes to the phpcpd command with your file paths and exclude flags. Developers then run composer quality:dupes before pushing, which makes duplication checks part of the normal local workflow. You can chain it with your existing test or lint scripts.
- Which PHP versions does sbrindle/phpcpd support and is it still maintained?
- It is a PHP command line tool distributed through Composer, so it runs on any PHP version allowed by its composer.json constraint, and Composer will refuse to install it if your PHP version does not satisfy that constraint. Check the GitHub repository for recent commits and tagged releases before relying on it. If you need stability, pin a specific version in your composer.json.