承接 shipmonk/name-collision-detector 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shipmonk/name-collision-detector

最新稳定版本:2.1.1

Composer 安装命令:

composer require shipmonk/name-collision-detector

包简介

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

README 文档

README

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:

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

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:

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

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) where you want to write any code (with 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

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

  • PHP 7.2 - PHP 8.4

统计信息

  • 总下载量: 1.65M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 36
  • 点击次数: 2
  • 依赖项目数: 25
  • 推荐数: 0

GitHub 信息

  • Stars: 34
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固