PHPackages                             athwari/laravel-method-overrider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. athwari/laravel-method-overrider

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

athwari/laravel-method-overrider
================================

Runtime method interception and overriding for Laravel

v1.1.0(4w ago)0771MITPHPPHP ^8.2CI passing

Since May 13Pushed 4w agoCompare

[ Source](https://github.com/athwari/laravel-method-overrider)[ Packagist](https://packagist.org/packages/athwari/laravel-method-overrider)[ Docs](https://github.com/athwari/laravel-method-overrider)[ GitHub Sponsors](https://github.com/athwari)[ RSS](/packages/athwari-laravel-method-overrider/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (6)Versions (6)Used By (1)

Laravel Method Overrider
========================

[](#laravel-method-overrider)

[![Latest Version on Packagist](https://camo.githubusercontent.com/82cf60c71264c54dbd31f77f1d09355ac8185c7d8ebae3faf916ec6a3a39fa1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617468776172692f6c61726176656c2d6d6574686f642d6f76657272696465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/athwari/laravel-method-overrider)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c8cd1c5738863f0437d8ac9dd4045e9ec1ed4c5e529ade2e1b95910c9914d64c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f617468776172692f6c61726176656c2d6d6574686f642d6f76657272696465722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/athwari/laravel-method-overrider/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/68ba7b58ac67d6978aec4b119328b9de7206f5be4001c0481355309935b891d1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f617468776172692f6c61726176656c2d6d6574686f642d6f76657272696465722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/athwari/laravel-method-overrider/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/bf971c19deae41885f1262d5d0498f83d64756483431c8104a36e56604a247d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617468776172692f6c61726176656c2d6d6574686f642d6f76657272696465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/athwari/laravel-method-overrider)

Runtime method interception and overriding for Laravel applications.

This package allows you to override instance and static methods on a class at runtime by generating a proxy class that delegates to an implementation closure.

Installation
------------

[](#installation)

Install the package with Composer:

```
composer require athwari/laravel-method-overrider
```

Laravel package auto-discovery is supported, so the service provider and facade are registered automatically.

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=method-overrider-config
```

The published config file is located at `config/method-overrider.php`.

### Default configuration

[](#default-configuration)

```
return [
    'ignore_final_methods' => true,
];
```

- `ignore_final_methods`: when `true`, final methods are skipped during override generation instead of throwing an exception.

Usage
-----

[](#usage)

Use the `MethodOverrider` facade to override methods on a target class.

### Override a method

[](#override-a-method)

```
use Athwari\MethodOverrider\Facades\MethodOverrider;

class TestService
{
    public function greet(string $name): string
    {
        return "Hello {$name}";
    }
}

$service = MethodOverrider::override(
    TestService::class,
    'greet',
    function ($original, $name) {
        return strtoupper($original($name));
    }
);

echo $service->greet('Taylor'); // HELLO TAYLOR
```

### Override multiple methods

[](#override-multiple-methods)

```
$service = MethodOverrider::override(
    TestService::class,
    ['greet', 'nullable'],
    [
        function ($original, $name) {
            return strtoupper($original($name));
        },
        function ($original, $name) {
            return $original($name);
        },
    ]
);
```

### Supported method signatures

[](#supported-method-signatures)

The package supports:

- nullable and union parameter types
- variadic parameters
- reference parameters
- static methods
- return types

Final methods are skipped when `ignore_final_methods` is enabled.

Exceptions
----------

[](#exceptions)

The package throws exceptions for invalid usage:

- `Athwari\MethodOverrider\Exceptions\ClassNotFoundException`
- `Athwari\MethodOverrider\Exceptions\MethodNotFoundException`
- `Athwari\MethodOverrider\Exceptions\InvalidImplementationException`

Testing
-------

[](#testing)

Run the test suite with Pest:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [athwari](https://github.com/athwari)
- [All Contributors](../../contributors)

License
-------

[](#license)

The package is open-source software licensed under the MIT License. Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance94

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

28d ago

Major Versions

v0.1.2-alpha → v1.0.02026-05-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/244ab61401b3fa5d1b2f60ca760064e43e86831b848ecc253a226ebaa5e771f2?d=identicon)[athwari](/maintainers/athwari)

---

Top Contributors

[![athwari](https://avatars.githubusercontent.com/u/1128182?v=4)](https://github.com/athwari "athwari (1 commits)")

---

Tags

laravelinterceptionoverrideathwarilaravel-method-overrider

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/athwari-laravel-method-overrider/health.svg)

```
[![Health](https://phpackages.com/badges/athwari-laravel-method-overrider/health.svg)](https://phpackages.com/packages/athwari-laravel-method-overrider)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[vinkius-labs/laravel-page-speed

Laravel Page Speed

2.5k9.6k1](/packages/vinkius-labs-laravel-page-speed)[emargareten/inertia-modal

Inertia Modal is a Laravel package that lets you implement backend-driven modal dialogs for Inertia apps.

90128.1k](/packages/emargareten-inertia-modal)[linkxtr/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

3614.9k](/packages/linkxtr-laravel-qrcode)[wearepixel/laravel-cart

A cart implementation for Laravel

1355.6k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
