degraciamathieu/php-arguments-detector
Detect and analyze function/method arguments in PHP using a lightweight, reflection-based approach. Useful for tooling that needs to inspect call signatures, validate inputs, or generate metadata about parameters and defaults across codebases.
App\Providers\ArgumentDetectorServiceProvider) to hook into Illuminate\Foundation\Bootstrap\RegisterProviders.php artisan argument:detect command for ad-hoc analysis.Illuminate\Pipeline to validate arguments in API routes (e.g., Route::middleware([ArgumentDetector::class])).composer require degraciamathieu/php-arguments-detector.| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Configure custom thresholds per class/method via annotations (e.g., @ArgumentDetector(ignore=true)). |
| Performance Overhead | Run as a pre-commit hook (not runtime); exclude tests/vendors via .argumentdetectorignore. |
| Laravel-Specific Edge Cases | Test with: |
method() helpers).app()->make()). |
| Maintenance Debt | Pair with Refactoring Tools (e.g., PHPStorm’s "Introduce Parameter Object") to automate fixes. |Request objects, Illuminate\Support\Collection methods)?pint/php-cs-fixer?| Component | Integration Strategy |
|---|---|
| Laravel Core | Leverage Service Container to bind the detector as a singleton. |
| PHPUnit Tests | Add a @method annotation test trait to validate argument counts in unit tests. |
| API Layer | Use Middleware to validate incoming request arguments (e.g., StoreUserRequest). |
| CLI Tools | Extend with a Laravel Artisan command for one-off scans. |
| IDE Plugins | Integrate with PHPStorm via Inspection Profile for real-time feedback. |
Phase 1: Static Analysis
composer require degraciamathieu/php-arguments-detector.composer.json:
"scripts": {
"post-autoload-dump": "ArgumentDetector\\Detector::analyze(__DIR__.'/app')"
}
.argumentdetectorignore:
/vendor/
/tests/
/config/
Phase 2: CI Enforcement
.github/workflows/laravel.yml:
- name: Argument Detector
run: composer argument:detect --fail-on-violation
Phase 3: Runtime Validation (Optional)
app/Http/Kernel.php:
protected $routeMiddleware = [
'validate.args' => \ArgumentDetector\Middleware\ArgumentValidator::class,
];
Route::post('/users', [UserController::class, 'store'])->middleware('validate.args');
Illuminate\Container\Container).composer argument:detect --dry-run to identify violations.@ArgumentDetector(ignore=true) and justify in PRs..env) for thresholds:
ARGUMENT_DETECTOR_THRESHOLD=5
Request objects).config/argument_detector.php:
'ignored_methods' => [
'App\Http\Controllers\UserController@store',
'App\Services\PaymentService::process',
],
composer dump-autoload).vendor/ and node_modules/.composer install).laravel-debugbar).app/ first, then expand to app/Modules/.| Failure Scenario | Impact | Recovery Plan |
|---|---|---|
| CI Build Fails | Blocked merges | Temporarily allow violations via --allow flag. |
| Runtime Middleware Crash | API downtime | Wrap in try-catch and log violations. |
| False Negative (Missed Violation) | Technical debt accumulates | Run periodic composer argument:detect --deep. |
How can I help you explore Laravel packages today?