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

Php Arguments Detector Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The package enforces method argument limits, aligning with clean code principles (e.g., Single Responsibility Principle, cyclomatic complexity reduction). Ideal for:
    • Legacy codebases with high-argument methods (e.g., Laravel controllers, service classes).
    • New projects adopting Domain-Driven Design (DDD) or CQRS where bounded contexts demand focused methods.
    • API layers (e.g., Laravel API resources) where excessive parameters may indicate poor separation of concerns.
  • Anti-Pattern Mitigation: Targets "God Methods" (methods >10 args) and "Parameter Object Hell" by enforcing thresholds (default: 5 args).
  • Static Analysis Fit: Complements Laravel’s PHPStan, Psalm, or PHPMD for pre-commit hooks (e.g., via GitHub Actions or Laravel Forge).

Integration Feasibility

  • Laravel-Specific Levers:
    • Service Providers: Register as a Laravel Event Listener (e.g., App\Providers\ArgumentDetectorServiceProvider) to hook into Illuminate\Foundation\Bootstrap\RegisterProviders.
    • Artisan Commands: Extend with a custom php artisan argument:detect command for ad-hoc analysis.
    • Middleware: Integrate with Illuminate\Pipeline to validate arguments in API routes (e.g., Route::middleware([ArgumentDetector::class])).
  • PHP Ecosystem:
    • PSR-12 Compliance: Works with any PSR-compliant codebase; no Laravel-specific dependencies.
    • Composer Autoloading: Zero-config if installed via composer require degraciamathieu/php-arguments-detector.

Technical Risk

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:
  • Closures/Lambdas (e.g., route callbacks).
  • Dynamic Method Calls (e.g., method() helpers).
  • Dependency Injection (e.g., app()->make()). | | Maintenance Debt | Pair with Refactoring Tools (e.g., PHPStorm’s "Introduce Parameter Object") to automate fixes. |

Key Questions

  1. Threshold Strategy:
    • Should thresholds be global (e.g., 5 args) or context-aware (e.g., 7 args for DTOs)?
    • How to handle Laravel-specific patterns (e.g., Request objects, Illuminate\Support\Collection methods)?
  2. Enforcement Mechanism:
    • Static Analysis (preferred) vs. Runtime Validation (e.g., middleware)?
    • Integration with CI/CD pipelines (e.g., fail builds on violations)?
  3. Tooling Synergy:
    • How to combine with PHPStan rules or Laravel’s pint/php-cs-fixer?
  4. Legacy Code:
    • Should the package whitelist existing violations or force refactoring?
  5. Team Adoption:
    • How to educate developers on alternatives (e.g., DTOs, Fluent Interfaces)?

Integration Approach

Stack Fit

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.

Migration Path

  1. Phase 1: Static Analysis

    • Install package: composer require degraciamathieu/php-arguments-detector.
    • Configure in composer.json:
      "scripts": {
        "post-autoload-dump": "ArgumentDetector\\Detector::analyze(__DIR__.'/app')"
      }
      
    • Exclude directories in .argumentdetectorignore:
      /vendor/
      /tests/
      /config/
      
  2. Phase 2: CI Enforcement

    • Add to .github/workflows/laravel.yml:
      - name: Argument Detector
        run: composer argument:detect --fail-on-violation
      
  3. Phase 3: Runtime Validation (Optional)

    • Register middleware in app/Http/Kernel.php:
      protected $routeMiddleware = [
          'validate.args' => \ArgumentDetector\Middleware\ArgumentValidator::class,
      ];
      
    • Apply to routes:
      Route::post('/users', [UserController::class, 'store'])->middleware('validate.args');
      

Compatibility

  • Laravel Versions: Works with LTS versions (8.x–10.x); test with PHP 8.0+ (due to named arguments).
  • Dependencies: No Laravel-specific dependencies; pure PHP 7.4+.
  • Conflicts:
    • PHPStan/Psalm: May report duplicate violations; configure priority rules.
    • Dynamic Proxies: Ignore Laravel’s service container proxies (e.g., Illuminate\Container\Container).

Sequencing

  1. Audit Existing Codebase:
    • Run composer argument:detect --dry-run to identify violations.
  2. Prioritize Refactoring:
    • Target high-impact methods (e.g., controllers with >7 args).
    • Use DTOs or Fluent Interfaces to reduce arguments.
  3. Iterative Enforcement:
    • Start with warnings in CI, then fail builds after 2 sprints.
  4. Document Exceptions:
    • Annotate ignored methods with @ArgumentDetector(ignore=true) and justify in PRs.

Operational Impact

Maintenance

  • Configuration Drift:
    • Risk: Custom thresholds may diverge across projects.
    • Mitigation: Use environment variables (e.g., .env) for thresholds:
      ARGUMENT_DETECTOR_THRESHOLD=5
      
  • False Positives:
    • Risk: Overly strict rules break legitimate patterns (e.g., Request objects).
    • Mitigation: Maintain a whitelist in config/argument_detector.php:
      'ignored_methods' => [
          'App\Http\Controllers\UserController@store',
          'App\Services\PaymentService::process',
      ],
      

Support

  • Developer Onboarding:
    • Training: Add a README section explaining:
      • Why argument limits matter (e.g., testability, readability).
      • How to refactor violations (e.g., extract methods, use DTOs).
    • Tooling: Integrate with Laravel Forge or Laravel Vapor for CI enforcement.
  • Troubleshooting:
    • Common Issues:
      • "Method not found" errors → Check autoloading (composer dump-autoload).
      • Performance slowdowns → Exclude vendor/ and node_modules/.

Scaling

  • Performance:
    • Static Analysis: Negligible overhead (runs once per composer install).
    • Runtime Validation: Add ~1ms per request (benchmark with laravel-debugbar).
  • Large Codebases:
    • Parallel Processing: Use PHP-PM or RoadRunner to scan directories in parallel.
    • Incremental Scanning: Focus on app/ first, then expand to app/Modules/.

Failure Modes

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.

Ramp-Up

  • Team Readiness:
    • Metrics: Track violation reduction over time (e.g., Jira custom field).
    • Incentives: Reward teams that eliminate violations (e.g., "Clean Code Champion" badge).
  • **Phased Rollout
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky