shipmonk/name-collision-detector
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 8.1 - PHP 8.5
shipmonk/name-collision-detector 适用场景与选型建议
shipmonk/name-collision-detector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.78M 次下载、GitHub Stars 达 34, 最近一次更新时间为 2022 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「autoload」 「autoloading」 「namespace」 「classname」 「collision」 「ambiguous」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shipmonk/name-collision-detector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shipmonk/name-collision-detector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shipmonk/name-collision-detector 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Environment processor and contexts autoloader
Simple autoloader that will autoload classes or traits with namespace prefix
MvcCore - Extension - Debug - Tracy - Panel Session - render and add into tracy debug panel $_SESSION content and \MvcCore\Session namespaces content.
Flexible storage solution for end-user data
Extension to autoload modules dynamically
Monolog cascade extension allows to configure loggers for a specific namespace/class (log4j style)
统计信息
- 总下载量: 2.78M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 30
- 依赖项目数: 40
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-21