PHPackages                             shipmonk/name-collision-detector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. shipmonk/name-collision-detector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

shipmonk/name-collision-detector
================================

Simple tool to find ambiguous classes or any other name duplicates within your project.

2.1.1(2y ago)362.1M—2.4%220MITPHPPHP ^7.2 || ^8.0CI passing

Since Dec 21Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/shipmonk-rnd/name-collision-detector)[ Packagist](https://packagist.org/packages/shipmonk/name-collision-detector)[ RSS](/packages/shipmonk-name-collision-detector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (9)Versions (8)Used By (20)

Name collision detector
=======================

[](#name-collision-detector)

Simple tool which allows you to detect if there are no types defined multiple times within the same namespace. This means that any ambiguous class, interface, enum, trait, constant or function is reported. Non-zero exit code is returned when any duplicate is found.

Installation:
-------------

[](#installation)

```
composer require --dev shipmonk/name-collision-detector
```

Usage:
------

[](#usage)

Check duplicate types:

```
vendor/bin/detect-collisions dir1 dir2 dir3 # relative to cwd
```

Example error output:

```
Foo\NamespacedClass2 is defined 2 times:
 > /tests/sample-collisions/file2.php:23
 > /tests/sample-collisions/file2.php:45

GlobalInterface1 is defined 2 times:
 > /tests/sample-collisions/file1.php:8
 > /tests/sample-collisions/file2.php:11

```

Example success output:

```
OK (no name collision found)
 * analysed files: 9867
 * excluded files: 0
 * elapsed time: 1.057 s

```

- Note the performance: **10 000 files takes few seconds**!

Configuration:
--------------

[](#configuration)

If file named `collision-detector.json` is present within current working directory, its contents are taken as configuration options. Possible config options:

```
{
    "scanPaths": ["src", "tests"], // files/directories to scan, relative to config file directory, glob not supported
    "excludePaths": ["tests/collisions"], // files/directories to exclude, relative to config file directory, glob not supported
    "fileExtensions": ["php"], // file extensions to parse
    "ignoreParseFailures": false // skip files with parse errors or not
}
```

Paths provided by CLI arguments have priority over those in `scanDirs`.

You can provide custom path to config file by `vendor/bin/detect-collisions --configuration path/to/config.json`

Reasoning
---------

[](#reasoning)

Having colliding classes within project can cause crazy headaches while debugging why something works only sometimes. Typically, you have PSR-4 autoloading which often solves this problem for you, but there are cases (like [PHPStan rules test files](https://github.com/shipmonk-rnd/phpstan-rules/tree/master/tests/Rule/data)) where you want to write any code (with [classmap](https://getcomposer.org/doc/04-schema.md#classmap) autoloading). And in such cases, the test may work when executed in standalone run, but fail when running all the tests together (depending on which class was autoloaded first). Therefore, having a collision detector in CI might be useful.

Composer's ambiguous class resolution
-------------------------------------

[](#composers-ambiguous-class-resolution)

Composer can also detect class duplicates and exit with non-zero, but it runs much slower and lacks function and constant detection. Using composer version `>= 2.8.1`, you can use:

```
composer dump --optimize --strict-ambiguous
```

Supported PHP versions
----------------------

[](#supported-php-versions)

- PHP 7.2 - PHP 8.4

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance55

Moderate activity, may be stable

Popularity52

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~109 days

Total

5

Last Release

808d ago

Major Versions

1.1.0 → 2.0.02023-09-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b545e3f9d982d538f11bc42b3dc2d186f706cef92c8bc8bc8f8788b08186ea5?d=identicon)[janedbal](/maintainers/janedbal)

![](https://www.gravatar.com/avatar/7a4170ebe9281cb76be91fe00f8eee307beb3e0744dfd40ba89d9c856372c7eb?d=identicon)[shipmonk](/maintainers/shipmonk)

---

Top Contributors

[![janedbal](https://avatars.githubusercontent.com/u/1993453?v=4)](https://github.com/janedbal "janedbal (38 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (36 commits)")[![JanTvrdik](https://avatars.githubusercontent.com/u/175109?v=4)](https://github.com/JanTvrdik "JanTvrdik (4 commits)")

---

Tags

ambiguousclassnamecollissionduplicatephpautoloadautoloadingnamespaceclassnamecollisionambiguous

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/shipmonk-name-collision-detector/health.svg)

```
[![Health](https://phpackages.com/badges/shipmonk-name-collision-detector/health.svg)](https://phpackages.com/packages/shipmonk-name-collision-detector)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.4k187.2M2.6k](/packages/composer-composer)[nette/robot-loader

🍀 Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.

89352.7M321](/packages/nette-robot-loader)[classpreloader/classpreloader

Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case

37642.4M32](/packages/classpreloader-classpreloader)[funkjedi/composer-include-files

Include files at a higher priority than autoload files.

1263.2M19](/packages/funkjedi-composer-include-files)[automattic/jetpack-autoloader

Creates a custom autoloader for a plugin or theme.

525.5M69](/packages/automattic-jetpack-autoloader)[typisttech/imposter-plugin

Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins.

158251.0k2](/packages/typisttech-imposter-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
