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

View on GitHub
Deep Wiki
Context7

Getting Started

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.

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 related mutators to suggest safe cleanup steps; apply with --dry-run first, review diffs, then commit.
  • Codebase measurement: The ported 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.
  • PHP upgrade planning: The ported 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.
  • Legacy upgrade path: The ported 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.
  • 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

  • 2.7.0 is a breaking release for scripts: 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.
  • Migrating off 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.
  • Migrating off 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.
  • Dry-run for mutators: Most commands modifying files (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.
  • File skipping uses 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.
  • Namespace-to-PSR-4 overwrites silently: Always back up or run --dry-run; the tool renames namespaces and expects src/ClassName.php → App\ClassName mapping. Verify no file collisions exist.
  • Keep measurement commands non-blocking: 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.
  • Windows console quirk: Older versions had broken progress bars on Windows with Symfony 6.4.24 — 2.7.0 is well past that, so upgrade rather than working around it.
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.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log