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

Patchwork Laravel Package

antecedent/patchwork

Patchwork is a PHP library for monkey patching: redefine functions, methods, and classes at runtime to ease testing and legacy refactors. Works with Composer and popular test tools, enabling stubs/mocks without changing existing code.

Deep Wiki
Context7

Product Decisions This Supports

  • Legacy System Modernization: Accelerate testing and integration of legacy PHP codebases without full refactoring, reducing technical debt incrementally.
  • Rapid Prototyping: Enable quick experimentation with new features or workflows by dynamically altering function behavior without modifying production code.
  • Testing Strategy: Expand test coverage for untestable legacy systems by intercepting and stubbing dependencies, improving CI/CD reliability.
  • Debugging & Hotfixes: Deploy temporary fixes or debugging hooks in production environments without redeploying code (e.g., logging, validation overrides).
  • Build vs. Buy: Justify adopting this package over custom solutions for runtime manipulation, saving dev time and reducing risk.
  • Roadmap Prioritization: Fast-track features dependent on legacy systems by bypassing refactor blockers (e.g., third-party SDKs, static classes).

When to Consider This Package

Adopt when:

  • Your team maintains large, untested legacy PHP codebases where refactoring is costly or politically risky.
  • You need to test global/static functions or built-ins (e.g., date(), file_get_contents()) without modifying source files.
  • Prototyping requires runtime behavior changes (e.g., A/B testing, feature flags with dynamic overrides).
  • Debugging complex interactions in production is critical, and traditional logging isn’t sufficient.
  • Your stack uses Laravel/PHP and lacks native DI for certain dependencies (e.g., legacy WordPress plugins, custom libraries).

Look elsewhere if:

  • Your codebase is already modular with dependency injection (consider Laravel’s built-in mocking or containers).
  • You need long-term runtime changes (use configuration files or feature flags instead).
  • The team lacks discipline to revert patches (risk of production bugs from lingering overrides).
  • Performance is critical (monkey patching adds runtime overhead; benchmark first).
  • You’re working in a strictly typed environment where runtime manipulation conflicts with type safety.

How to Pitch It (Stakeholders)

For Executives: "Patchwork lets us test and extend legacy PHP systems without rewriting them—saving 6–12 months of dev effort. For example, we can stub out a third-party payment gateway’s static methods to test our checkout flow, or dynamically inject logging into production to debug a critical bug. This reduces risk in modernizing our stack while keeping legacy systems running. The MIT license and active maintenance make it a low-risk choice."

For Engineers: *"This is like PHP’s dd() for functions—you can override any global/static method at runtime to:

  • Mock dependencies in legacy tests (e.g., Mail::send() → return a fake response).
  • Debug live issues by intercepting calls (e.g., log every User::find() with slow queries).
  • Prototype features without touching production code (e.g., override Auth::attempt() to simulate admin sessions). It’s lightweight, works with Laravel, and avoids the pitfalls of manual hacks. Use it for tests, debugging, or temporary fixes—never for permanent changes."*
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
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
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests