Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Swiss Knife Laravel Package

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).

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

Use the tool as a multi-purpose hygiene agent across the development lifecycle:

  • Pre-commit / CI hygiene: Run check-conflicts, check-commented-code, and find-multi-classes to enforce baseline quality and PSR-4 compliance before merging.
  • Refactoring guidance: Use finalize-classes, privatize-constants, and spot-lazy-traits to suggest safe cleanup steps; apply with --dry-run first, review diffs, then commit.
  • Test scaffolding: Leverage 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.
  • Symfony optimization: Run generate-symfony-config-builders and split-config-per-package to modernize config structures and enable IDE autocompletion and static analysis.
  • Data-driven refactor decisions: Use search-regex to quantify legacy patterns (e.g., deprecated $this->get() usage) before targeted Rector sets or manual removal.

Gotchas and Tips

  • Dry-run is implicit for mutators: Most commands modifying files (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.
  • File skipping uses 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 has no container magic: It only mocks unresolved constructor parameters. If a typehint is not injectable (e.g., scalar, interface not bound in DI), tests may fail—ensure auto-wiring works before relying on MockWire.
  • Namespace-to-PSR-4 overwrites silently: Always back up or run --dry-run; the tool renames namespaces and expects src/ClassName.phpApp\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.
  • Windows console quirk: Prior to 2.3.3, progress bars broke on Windows in Symfony 6.4.24—upgrade to avoid visual glitches, though functionality remains correct.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport