kerrialn/migrator
Composer 安装命令:
composer require kerrialn/migrator
包简介
README 文档
README
Migrator is a global CLI tool that analyses the complexity of upgrading or migrating a PHP project. Run it against any codebase to get a scored report across framework coupling, database coupling, dependency compatibility, architecture quality, test coverage, and codebase size.
This is a global tool — do not install it as a project dependency. It runs on your development machine and analyses projects by path.
Requirements
- PHP 8.2+
Installation
Install globally with Composer:
composer global require kerrialn/migrator
Then ensure the global Composer bin directory is in your PATH.
Mac / Linux — add to ~/.zshrc or ~/.bashrc:
export PATH="$HOME/.composer/vendor/bin:$PATH"
Reload your shell:
source ~/.zshrc
Windows — run in PowerShell (adds permanently for your user):
[System.Environment]::SetEnvironmentVariable( "PATH", $env:PATH + ";$env:APPDATA\Composer\vendor\bin", "User" )
Then restart your terminal. Alternatively, add %APPDATA%\Composer\vendor\bin via System Properties → Environment Variables.
Usage
Navigate to the project you want to analyse and run:
cd /path/to/your/project
migrator analyse
The tool will prompt you for migration or upgrade mode, then source and target framework or PHP version.
On the first run, create a migrator.php config file in the project root. You can commit this file to persist your configuration.
Configuration
<?php declare(strict_types=1); use KerrialNewham\Migrator\Config\Config; return new Config( path: getcwd(), exclude: [ 'vendor', 'tests', 'node_modules', 'var', ], );
Options
| Option | Type | Description |
|---|---|---|
path |
string |
Root path of the project to analyse. Defaults to getcwd(). |
exclude |
string[] |
Directories to skip entirely (vendor, cache, assets, etc.). |
legacyDirs |
string[] |
Directories containing legacy framework code being migrated away from (see below). |
Mid-migration analysis with legacyDirs
When a project is mid-migration, legacy and new code coexist. Including the legacy directories inflates coupling scores and hides the quality of the new code layer. Use legacyDirs to separate them:
return new Config( path: getcwd(), exclude: [ 'vendor', 'tests', 'node_modules', 'var', ], legacyDirs: [ 'addons/main', // legacy CI3 modules being migrated away 'system/cms', // legacy CI3 application layer ], );
The tool will analyse the new code layer independently and append a Legacy Code Remaining section to the report showing:
- Legacy file count vs new code file count
- Migration progress as a percentage of files migrated
- Legacy coupling score with a plain-English label (e.g. heavily coupled — significant rewrite work remains)
Use the pre-migration score (no legacyDirs) as your baseline difficulty rating. Use legacyDirs during migration to track progress.
What it analyses
Upgrade
Scores how difficult it would be to upgrade the project to a newer PHP version:
| Metric | Weight |
|---|---|
| Framework Version Upgradability | 35% |
| Dependencies Upgradability | 30% |
| PHP Version Upgradability | 20% |
| Codebase Size | 15% |
Scores are rated:
| Range | Label |
|---|---|
| 0–49 | Difficult Upgrade |
| 50–79 | Medium Upgrade |
| 80–100 | Easy Upgrade |
Migration
Scores how difficult it would be to migrate the project to a different framework:
| Metric | Weight | What it measures |
|---|---|---|
| Framework Coupling | 30% | How many files reference framework-specific patterns (namespaces, helpers, base classes, facades) |
| Database Coupling | 20% | Database abstraction layer quality — Doctrine scores highest, CI3 Active Record and raw SQL lowest |
| Dependency Compatibility | 10% | Composer packages that conflict with or don't exist for the target framework |
| Architecture Quality | 25% | Presence of service layer, repositories, interfaces, constructor DI, and Data Mapper ORM entities |
| Test Coverage | 5% | Ratio of test files; penalises framework-coupled tests |
| Codebase Size | 10% | Logarithmic penalty for large codebases |
Scores are rated:
| Range | Label |
|---|---|
| 0–35 | Extremely Difficult |
| 35–55 | Very Difficult |
| 55–70 | Difficult |
| 70–85 | Moderate |
| 85–100 | Straightforward |
Supported frameworks
Detection and coupling analysis is supported for:
- Symfony
- Laravel
- CodeIgniter (CI3 and CI4)
- Yii
- Zend / Laminas
- CakePHP
- Phalcon
- Tempest
kerrialn/migrator 适用场景与选型建议
kerrialn/migrator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 49 次下载、GitHub Stars 达 7, 最近一次更新时间为 2025 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 kerrialn/migrator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kerrialn/migrator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-21