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

Surveyor Laravel Package

laravel/surveyor

Beta Laravel tool for mostly static analysis of PHP/Laravel apps. Parses files/classes to extract rich metadata (classes, methods, properties, types) and can inspect models and container bindings for extra detail. Returns structured results for other tools.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Eloquent Builder & Query Method Resolution (PR #44, #46):

    • Hardened Query Analysis: Fixes critical gaps in Eloquent Builder method resolution, enabling accurate analysis of:
      • Dynamic Query Chains: Correctly resolves methods like where(), orderBy(), and select() in builder mixins (e.g., @mixin in Blade or custom traits).
      • Integer Range Types: Resolves issues with range-based queries (e.g., whereBetween(), whereIn() with array ranges), improving SQL injection detection and query optimization suggestions.
      • Generics Propagation: PR #46 ensures type safety in nested builder method chains (e.g., User::where('active', true)->with('posts')->get()), critical for API response validation and DTO generation.
    • Laravel-Specific Synergy: Directly addresses common Eloquent anti-patterns:
      • Mixin Misuse: Detects incorrect @mixin usage in Blade or service providers.
      • Type Inference Failures: Fixes false positives in query builder method chaining (e.g., Model::query()->where(...)->get()).
      • Builder Method Overloads: Resolves ambiguities in custom query builder extensions.
  • Interface & Class Analysis (PR #40):

    • Enhanced Static Analysis: Improves interface implementation validation and abstract class resolution, enabling:
      • Contract Enforcement: Detects missing method implementations in service contracts (e.g., Illuminate\Contracts\Auth\Authenticatable).
      • Trait Composition: Better handles conflicting trait methods in Eloquent models or service providers.
      • Dependency Injection: Validates constructor parameter types against interfaces (e.g., RepositoryInterface).
  • PHP Keyword Resolution (PR #43):

    • Method Name Collisions: Fixes parsing of methods named after PHP reserved keywords (e.g., class, abstract, final), which are common in Laravel:
      • Custom Accessors/Mutators: Resolves getClass() or setAbstract() in model attributes.
      • Dynamic Proxies: Improves analysis of Laravel’s service container proxies (e.g., Illuminate\Container\Container::make()).

Integration Feasibility

  • Eloquent Query Safety:

    • SQL Injection Mitigation: PR #44/#46 reduces false negatives in query analysis, improving security scanning for:
      • Dynamic SQL: Detects unsafe DB::raw() or whereRaw() usage.
      • Mass Assignment: Validates fillable/guarded against query-generated data.
    • Performance Optimization: Enables query plan suggestions (e.g., "Add select() to avoid N+1 queries in with()").
  • Interface & Contract Compliance:

    • Service Layer Validation: Detects broken dependencies in:
      • Repositories: Ensures find()/create() methods adhere to RepositoryInterface.
      • Policies: Validates before()/authorize() against Illuminate\Auth\Access\HandlesAuthorization.
    • Testing Framework Integration: Supports property-based testing of interface contracts (e.g., with PestPHP or PHPUnit).
  • Backward Compatibility:

    • No Breaking Changes: All fixes are opt-in improvements with no API modifications.
    • Deprecation-Free: No removed features; only enhanced precision.

Technical Risk

  • Eloquent Builder Complexity:

    • Custom Query Builders: PR #44/#46 may miss edge cases in:
      • Third-Party Builders: E.g., October\Rain\Database\Builder or Spatie\QueryBuilder.
      • Dynamic Method Calls: call_user_func_array()-based query builders.
      • Macro Conflicts: Overloaded builder methods (e.g., where() macros clashing with standard methods).
    • Mitigation: Test with:
      // Custom builder example
      $query->macro('customWhere', fn($field) => $query->where($field, 'test'));
      // Verify Surveyor resolves `customWhere` correctly.
      
  • Interface Analysis Edge Cases:

    • PHP 8.1+ Attributes: PR #40 may not fully resolve attribute-based interfaces (e.g., #[\ReturnTypeWillChange]).
    • Dynamic Interfaces: Interfaces generated via runtime reflection (e.g., new class implements Foo { ... }).
    • Mitigation: Profile with:
      composer survey --rules=Interfaces --profile
      
  • Performance Impact:

    • Generics Propagation (PR #46): May introduce overhead in large query chains.
      • Test with a benchmark script:
        $builder = User::query();
        for ($i = 0; $i < 100; $i++) {
            $builder->where("field_$i", $i);
        }
        $builder->get();
        
    • Cache Behavior: PR #46’s generics analysis may invalidate more cache entries than v0.2.3.
  • PHP Keyword Collisions (PR #43):

    • False Positives: Methods like getAbstract() might trigger unexpected warnings.
    • Mitigation: Whitelist known Laravel patterns in .surveyor.php:
      return [
          'rules' => [
              'Methods' => [
                  'ignore' => ['getAbstract', 'setFinal'], // If intentional
              ],
          ],
      ];
      

Key Questions

  1. Eloquent Query Reliability:

    • How critical are query builder method chains in your codebase? If you rely on complex builder extensions (e.g., custom macros), validate PR #44/#46’s coverage.
    • Do you use third-party query builders (e.g., Spatie, October)? Test their compatibility with the new resolution logic.
  2. Interface & Contract Enforcement:

    • Are you using service contracts (e.g., RepositoryInterface, Policy)? PR #40 may expose missing implementations in existing code.
    • How strict is your dependency injection? The fixes may reveal type mismatches in constructor parameters.
  3. PHP Keyword Usage:

    • Do you have methods named after PHP keywords (e.g., getClass, setAbstract)? PR #43’s fix may alter their analysis.
    • Are you using dynamic proxies (e.g., Laravel’s service container)? Verify their parsing.
  4. Performance Trade-offs:

    • Are you running Surveyor in CI/CD with tight time budgets? PR #46’s generics analysis may increase runtime.
    • Do you use distributed caching (e.g., Redis) for Surveyor results? This can offset cache invalidation overhead.
  5. Migration Strategy:

    • Should you pin to 0.2.4 immediately, or wait for v1.0 for broader stability?
    • If using custom Surveyor rules, test them against the new:
      • Eloquent builder resolution.
      • Interface analysis.
      • Generics propagation.
  6. Failure Mode Testing:

    • Simulate custom query builder conflicts to validate PR #44/#46:
      // Test custom macro resolution
      DB::macro('unsafeWhere', fn($field) => DB::where($field, 'hack'));
      // Ensure Surveyor flags this as unsafe.
      
    • Test interface inheritance with complex traits:
      trait HasTimestamps {}
      class Model extends Illuminate\Database\Eloquent\Model {
          use HasTimestamps;
      }
      // Verify `created_at`/`updated_at` are correctly resolved.
      

Integration Approach

Stack Fit

  • Eloquent Ecosystem:

    • Query Builder: PR #44/#46 enables deep integration with:
      • Laravel Scout: Analyze indexable query patterns.
      • Spatie Query Builder: Validate custom syntax.
      • API Resource Queries: Type-check Resource::collection() with filtered queries.
    • Model Events: Better resolution of observables() and dispatchesEvents().
    • Database Observers: Validate event method signatures (e.g., retrieved(), saved()).
  • Interface-Driven Development:

    • Laravel Packages: Validate contracts for:
      • Laravel Nova: NovaResource implementations.
      • Laravel Fortify: Authenticatable compliance.
      • Laravel Cashier: Billable interfaces.
    • Testing: Integrate with PestPHP’s assertImplements() or PHPUnit’s implementsInterface().
  • PHP Static Analysis Tools:

    • Psalm/PHPStan: Complements Surveyor’s Eloquent-specific fixes (e.g., query builder generics).
    • PHP-CS-Fixer: Use Surveyor’s interface validation to enforce consistent method signatures.
    • Infection: Target **interface-breaking mutations
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai