rector/swiss-knife
Swiss Knife for upgrades: CLI tools to keep codebases clean and PSR-4 compliant. Detect git merge conflicts and commented-out code, find multiple classes per file, fix namespaces to match PSR-4 roots, and finalize classes without children (with skips for mocks/files).
Install the package as a dev dependency: composer require rector/swiss-knife --dev. Start by integrating one or two commands into your CI pipeline—check-conflicts to prevent merge conflict commits and check-commented-code to catch accidentally left commented-out code. Run them early in your workflow and treat failures as blocking issues.
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 spot-lazy-traits to suggest safe cleanup steps; apply with --dry-run first, review diffs, then commit.MockWire in unit tests to simplify constructor-heavy services—pass only mocks needed for the current test, leaving dependencies auto-mocked and test intent clearer.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.finalize-classes, privatize-constants, namespace-to-psr-4) act directly—always use --dry-run first to preview changes. A recent release (2.3.3) now explicitly warns when --dry-run is used.fnmatch(): Patterns like --skip-file '*Controller.php' work with shell-style globs, not regex—test with vendor/bin/swiss-knife command . --dry-run to confirm exclusions.MockWire.--dry-run; the tool renames namespaces and expects src/ClassName.php → App\ClassName mapping. Verify no file collisions exist.spot-lazy-traits default is strict: Traits used ≤2 times get flagged. Increase --max-used for libraries where traits are intentionally reused across internal implementations.How can I help you explore Laravel packages today?