- What is mspirkov/yii2-rector used for?
- It is a Rector extension that adds Yii2-specific refactoring rules to PHP projects. It automates routine code modernization and framework upgrades by applying configurable rulesets to Yii2 codebases. You use it with Rector to reduce manual edits while keeping behavior predictable.
- How do I install mspirkov/yii2-rector?
- Install it as a development dependency with Composer using composer require --dev mspirkov/yii2-rector. Rector itself must also be available in the project so you can run the vendor/bin/rector command. After installation, register the package's Yii2 rulesets in your rector.php configuration.
- How do I configure Yii2 Rector rules in rector.php?
- Add the package's Yii2 ruleset classes to the sets() array in your existing rector.php file. The extension is designed to integrate with normal Rector workflows, so you can combine Yii2 rules with your own paths and skip settings. Start with a limited ruleset and expand it as you review changes.
- Which PHP and Yii2 versions does mspirkov/yii2-rector support?
- The package is described as supporting modern PHP and Yii2 versions, and it is intended for current Composer-based Yii2 applications. Exact PHP and Yii2 version constraints should be checked in the package's composer.json and README before upgrading. This is important if you maintain older legacy projects with pinned framework versions.
- What Yii2 rulesets are included in mspirkov/yii2-rector?
- The extension provides ready-to-use Yii2 rulesets for common migrations and legacy pattern refactorings. The rules are configurable so you can adopt them incrementally rather than applying every change at once. Refer to the README for the current list of rulesets and what each one changes.
- Can I use mspirkov/yii2-rector in a Laravel project?
- No, this package provides Yii2-specific Rector rules and is aimed at Yii2 applications. Laravel projects should use Laravel-oriented Rector rulesets instead. You can still use Rector itself in Laravel, but this package's rules target Yii2 patterns.
- How do I preview Yii2 Rector changes before applying them?
- Run Rector with the --dry-run option to see proposed diffs without modifying files. Review the output for the Yii2 rules you enabled, then run Rector without --dry-run to apply the changes. Commit or back up your code first so you can compare and revert if needed.
- Is mspirkov/yii2-rector safe for production Yii2 code?
- It is designed for automated refactoring with predictable behavior, but any automated code change should be reviewed and tested. Run it on a branch, use dry runs, and execute your test suite after applying rules. Incremental adoption with a limited ruleset reduces risk in production codebases.
- How do I upgrade legacy Yii2 code incrementally with Rector?
- Configure only the rulesets relevant to the first migration step, then run Rector and review the diff. Once tests pass, enable the next set of Yii2 rules and repeat. This incremental approach keeps changes manageable and makes it easier to isolate unexpected refactorings.
- What are alternatives to mspirkov/yii2-rector for Yii2 upgrades?
- Alternatives include manual refactoring, custom Rector rules, and other Yii2-focused upgrade tools if available. Rector's own built-in rules can also handle general PHP modernization alongside Yii2-specific rules. The best choice depends on how much legacy Yii2 code you need to migrate and whether you want prebuilt rulesets.