Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpcpd Laravel Package

johnatas-x/phpcpd

Laravel-friendly wrapper for PHP Copy/Paste Detector (PHPCPD) to spot duplicated code in your PHP projects. Run duplication checks from your tooling/CI and get actionable reports to reduce redundancy and improve maintainability.

View on GitHub
Deep Wiki
Context7

Copy/Paste Detector (CPD) for PHP code.

Frequently asked questions about Phpcpd
How do I integrate phpcpd into my Laravel project’s CI/CD pipeline?
Use GitHub Actions, GitLab CI, or CircleCI to run `phpcpd` as a dedicated job. For example, in GitHub Actions, add a step with `php phpcpd.phar --min-tokens=100 --exclude=vendor/`, then configure thresholds to block PRs if duplicates exceed a set percentage. Ensure the PHAR is cached or installed globally for faster execution.
Can phpcpd work with Laravel’s Artisan commands?
Yes, wrap `phpcpd.phar` in a custom Artisan command (e.g., `php artisan phpcpd:check`) to run scans on demand. Use the `--report=json` flag to parse results programmatically, or output to HTML for developer dashboards. Exclude Laravel’s `vendor/` and `bootstrap/cache/` directories to avoid false positives.
What PHP version and Laravel compatibility does phpcpd support?
phpcpd requires PHP 8.1+ (matching Laravel’s LTS support). Test it with your Laravel version by running `php phpcpd.phar --version` first. For Laravel 10+, ensure no conflicts with Symfony’s Console component, which phpcpd depends on. Exclude generated files like `bootstrap/cache/` to avoid errors.
How do I configure duplicate detection thresholds to avoid false positives?
Start with `--min-tokens=50` (adjust based on your codebase) to ignore trivial duplicates. Use `--fuzzy` for semantic similarity checks, but balance it with `--fuzzy-limit` to reduce noise. Test thresholds locally on a subset of files before enforcing them in CI. Laravel’s test suite is a good starting point for validation.
Is phpcpd safe to run in production or should it only be used in CI?
phpcpd is a static analysis tool and poses no runtime risk, so it’s safe to run in CI or staging. Avoid running it in production unless debugging a specific issue. Use `--exclude=app/` or similar to limit scans to non-critical paths. For CI, cache the PHAR to avoid redundant downloads.
How can I exclude specific files or directories from phpcpd scans?
Use the `--exclude` flag to skip directories like `vendor/`, `bootstrap/cache/`, or test files. For example: `phpcpd.phar --exclude=vendor/ --exclude=tests/Unit/`. To exclude files matching a pattern, use `--exclude=*.php` with a custom script or combine with `find` in CI. Laravel’s `config/` and `database/` directories often don’t need scanning.
What are the alternatives to phpcpd for Laravel projects?
Consider **Simian** (Java-based, cross-language) for large projects or **PMD Copy/Paste Detector** (Java) for advanced rule sets. For PHP-only, **PHPMD** (PHP Mess Detector) includes CPD features. If you prefer Composer-based tools, **roave/security-advisories` or `phpstan/phpstan` (with custom rules) can complement phpcpd. Evaluate based on ease of CI integration and report formats.
How do I handle false positives in phpcpd reports for Laravel?
False positives often occur in boilerplate code (e.g., Eloquent model stubs) or generated files. Use `--exclude` to whitelist problematic paths, or adjust `--min-tokens` upward. For Laravel, exclude `app/Models/` if duplicates are expected in base models. Document exclusions in your team’s coding standards to maintain consistency.
Can phpcpd detect duplicates across multiple Laravel modules or packages?
Yes, phpcpd scans entire directories recursively. For monorepos or multi-package Laravel projects, run it on the root directory: `phpcpd.phar --fuzzy ./`. To optimize performance, split scans by module in CI (e.g., `phpcpd.phar --exclude=*/packages/* ./app`). Use `--report=json` to aggregate results across runs.
How do I visualize phpcpd results in my Laravel project?
Generate an HTML report with `--report=html` and serve it via Laravel’s `public/` directory or a dashboard like **Laravel Nova**. For IDE integration, use VSCode’s **PHP-CPD** extension to highlight duplicates inline. Parse JSON reports with Laravel’s `collect()` to build custom dashboards or Slack alerts for critical violations.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky