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

Name Collision Detector Laravel Package

shipmonk/name-collision-detector

Fast CLI tool to detect duplicate names in PHP code: classes, interfaces, traits, enums, functions, and constants defined multiple times in the same namespace. Scans thousands of files in seconds, supports config/excludes, exits non-zero on collisions.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package as a development dependency and run it on your source directories:

composer require --dev shipmonk/name-collision-detector
vendor/bin/detect-collisions src

Start with scanning your src/ directory. The tool will recursively scan all .php files and report any duplicate class, interface, trait, enum, function, or constant names within the same namespace — including global scope. A zero exit code means no collisions; non-zero indicates failures (useful in CI).

Implementation Patterns

  • CI Integration: Add to your pipeline (e.g., GitHub Actions, GitLab CI) with vendor/bin/detect-collisions src tests --configuration .collision-detector.json to enforce uniqueness before merging.
  • Local Development: Run before committing, especially after large refactors or when using classmap autoloading for test fixtures.
  • Config-Driven Scanning: Use collision-detector.json to define scanPaths, excludePaths, and fileExtensions for granular control (e.g., exclude test fixtures that intentionally duplicate names for isolation).
  • Compare with Composer’s Strict Ambiguous Mode: While composer dump --optimize --strict-ambiguous catches class duplicates, this tool adds coverage for functions, constants, and enums, and is significantly faster.

Gotchas and Tips

  • CLI args override config: Paths passed directly on CLI (vendor/bin/detect-collisions dir1) replace scanPaths from config, not augment it — be explicit.
  • Exclusions are relative to config file, not cwd — e.g., "excludePaths": ["tests/fixtures"] in .collision-detector.json means ./tests/fixtures, not ./vendor/bin/../tests/fixtures.
  • Invalid JSON throws an exception (since v2.1.1), but ensure your collision-detector.json is valid JSON5 (supports comments, trailing commas) — tools like jq or online validators help.
  • Parse failures are fatal by default (ignoreParseFailures: false). If you have intentionally malformed test files (e.g., invalid syntax for testing PHPStan), set this to true.
  • No glob support in paths — avoid src/* or tests/**/Data; list directories explicitly.
  • Performance note: Despite scanning 10k+ files in ~1s, complex polyfills or massive codebases may benefit from narrowing scanPaths or excluding test assets.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport