rector/swiss-knife
Swiss Knife is a CLI toolkit for PHP/Laravel upgrades: detect Git conflict markers and commented code, find multiple classes per file, align namespaces to PSR-4 roots, and finalize childless classes. Add its checks to CI and refactoring workflows.
Install the package as a dev dependency: composer require rector/swiss-knife --dev. The 2.7.0 release supports PHP 7.4 through 8.5, so it can run in CI on the same matrix as your application. Before wiring anything up, run vendor/bin/swiss-knife list to see the current command set — 2.7.0 pruned the command list, so older blog posts and snippets may reference commands that no longer exist. Then start with the two cheapest wins: check-conflicts (prevents committing merge markers) and check-commented-code (catches dead commented-out code). Put them early in the pipeline and treat failures as blocking.
Use the tool as a multi-purpose hygiene agent across the development lifecycle:
check-conflicts, check-commented-code, and find-multi-classes to enforce baseline quality and PSR-4 compliance before merging.finalize-classes, privatize-constants, and related mutators to suggest safe cleanup steps; apply with --dry-run first, review diffs, then commit.measure command (formerly tomasvotruba/lines) reports size and complexity metrics — lines, class/method counts, longest methods, coupling — which is the fastest way to justify or scope a refactor. Commit the output or diff it between releases to show whether a cleanup effort actually moved the needle.features command counts usage of language features across the codebase, so you can quantify how far a project already is from a target PHP version (attributes, promoted properties, readonly, enums, etc.) before scheduling the upgrade.rector/jack commands run Rector rules one at a time and report which ones apply cleanly to your code. Use this to pick an incremental rule set for a legacy upgrade instead of running a big Rector set blind and drowning in a thousand-file diff.generate-symfony-config-builders and split-config-per-package to modernize config structures and enable IDE autocompletion and static analysis.search-regex to quantify legacy patterns (e.g., deprecated $this->get() usage) before targeted Rector sets or manual removal.spot-lazy-traits was dropped in favour of a Symfony PHPStan rule, and MockWire plus several low-value commands were removed. Audit your CI config, composer scripts, and Makefiles for those names before upgrading the constraint, and re-run list to confirm what survived.MockWire: Tests relying on partial constructor mocking need to move to plain PHPUnit mocks, createMock(), or a dedicated mocking helper. This is the one removal that requires touching test code rather than just config.spot-lazy-traits: The replacement is a static-analysis rule, so the check moves from a one-off CLI run into your PHPStan pipeline. Add the symplify rule to phpstan.neon and run PHPStan in CI, otherwise you silently lose the check at the same moment the command disappears.finalize-classes, privatize-constants, namespace-to-psr-4) act directly — always use --dry-run first to preview changes. Recent releases warn explicitly when --dry-run is used, so treat the warning as a reminder, not an error.fnmatch(): Patterns like --skip-file '*Controller.php' are shell-style globs, not regex — test with vendor/bin/swiss-knife <command> . --dry-run to confirm exclusions.--dry-run; the tool renames namespaces and expects src/ClassName.php → App\ClassName mapping. Verify no file collisions exist.measure, features, and the jack commands are reporting tools — wire them as informational CI steps or local tasks rather than hard gates, otherwise a metrics change will block unrelated PRs.How can I help you explore Laravel packages today?