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

Classtools Laravel Package

hanneskod/classtools

Scan the filesystem for PHP classes, interfaces, and traits using Symfony Finder. Build a class-to-file map, detect parse/syntax errors, and iterate results as ReflectionClass objects, with optional autoloading for discovered classes.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Codebase Introspection: Perfect for Laravel’s need to dynamically analyze classes (e.g., service providers, event listeners, or custom macros). Aligns with Laravel’s modularity (plugins, packages, themes).
    • Reflection + Filesystem: Combines ReflectionClass (runtime) with filesystem scanning (compile-time), enabling tools like:
      • Dynamic Service Registration: Auto-discover classes implementing Illuminate\Contracts\Auth\Authenticatable.
      • Migration Helpers: Identify breaking changes by comparing class signatures across versions.
      • Code Quality: Flag unused classes or violate dependency rules (e.g., "No new in App\Services").
    • Filtering Flexibility: Chainable filters (type(), inNamespace(), where()) mirror Laravel’s Eloquent/Collection methods, easing adoption.
    • Transformer Pipeline: Enables code generation (e.g., converting classes to API specs, DTOs, or documentation) without manual templates.
  • Gaps:

    • Laravel-Specific Abstractions: No native support for Laravel’s Container, ServiceProvider, or Facade system. Requires custom bridges (e.g., wrapping ClassIterator in a Laravel service).
    • Performance: Reflection and filesystem scans add overhead. Risk of:
      • Slow Boot Time: If used in boot() or register() methods.
      • Memory Spikes: Large codebases may exhaust memory during scans.
    • Limited AST Capabilities: Cannot parse/modify class bodies (e.g., adding methods). For advanced transformations, pair with nikic/PHP-Parser.
    • Windows Path Handling: Assumes Unix paths; may fail on Windows servers without path normalization.

Integration Feasibility

  • Core Laravel Compatibility:

    • Pros:
      • Composer Integration: Zero-conf via composer require hanneskod/classtools.
      • Symfony Finder: Already used in Laravel’s files() helper and Illuminate\Filesystem.
      • PHP SPL: Works with Laravel’s SplFileInfo and Traversable interfaces.
    • Cons:
      • No Laravel Service Provider: Requires manual registration (e.g., in AppServiceProvider).
      • Autoloader Conflicts: enableAutoloading() may interfere with Laravel’s ClassLoader if not isolated.
      • Artisan Command Focus: Best suited for CLI tools (e.g., php artisan scan:classes) rather than runtime logic.
  • Key Integration Points:

    Laravel Feature Integration Approach Risk
    Service Container Bind ClassIterator as a singleton or context-bound service in AppServiceProvider. High (Reflection + Container)
    Artisan Commands Create custom commands (e.g., scan:classes, generate:api) using ClassIterator. Low
    Facades/Macros Wrap ClassIterator methods in a Facade for DSL-like syntax (e.g., ClassTools::scan()). Medium (Magic Method Overhead)
    Event System Trigger events (e.g., ClassesDiscovered) to notify other services of scan results. Low
    Testing (PHPUnit) Use in DataProvider or Extension traits to dynamically load test classes. Low

Technical Risk

  • Critical Risks:

    1. Reflection + Autoloader Conflicts:
      • Scenario: enableAutoloading() triggers Laravel’s autoloader recursively, causing infinite loops or memory exhaustion.
      • Mitigation: Isolate scans in a separate process (e.g., Artisan command) or use spl_autoload_register() temporarily.
    2. Performance Bottlenecks:
      • Scenario: Scanning 10K+ classes during boot time freezes the application.
      • Mitigation:
        • Cache results in bootstrap/cache/ with a TTL (e.g., 1 hour).
        • Run scans asynchronously (e.g., Laravel Queues or Horizon).
    3. Namespace/Class Collisions:
      • Scenario: Custom filters or transformers conflict with Laravel’s classes (e.g., Illuminate\Support\Collection).
      • Mitigation: Use fully qualified namespaces (e.g., \hanneskod\classtools\Filter\Type) and test against Laravel’s core.
    4. Error Handling:
      • Scenario: getErrors() returns raw PHP parse errors, which don’t integrate with Laravel’s exception system.
      • Mitigation: Normalize errors into Laravel exceptions (e.g., ClassDiscoveryException).
  • Medium Risks:

    • Windows Path Handling: May fail on Windows servers if paths aren’t normalized (e.g., str_replace('\\', '/', $path)).
    • Lack of Laravel-Specific Features: No built-in support for Laravel’s bind(), tag(), or when() container methods.
    • Documentation Gaps: README lacks Laravel-specific examples (e.g., "How to auto-register services").
  • Low Risks:

    • License (WTFPL): Permissive but implies no support. Mitigate by contributing fixes upstream.
    • Maturity: Low stars/dependents suggest untested edge cases, but core functionality is stable.

Key Questions

  1. Performance:
    • How to benchmark scan times for our codebase size (e.g., 5K vs. 50K classes)?
    • What’s the memory footprint of getClassMap() vs. iterating with ReflectionClass?
  2. Laravel Integration:
    • How to bind ClassIterator to Laravel’s IoC without autoloader conflicts?
    • Can we extend it to support Laravel’s bind() or tag() methods for dynamic service registration?
  3. Error Handling:
    • How to integrate getErrors() with Laravel’s exception system (e.g., throw new ClassDiscoveryException($errors))?
  4. Use Case Validation:
    • What are the top 3 Laravel-specific use cases (e.g., auto-service registration, migration tools)?
    • How would this compare to alternatives like php-parser or roave/security-advisories?
  5. Maintenance:
    • Who would own updates (e.g., bug fixes, Laravel version compatibility)?
    • How to handle upstream changes (e.g., Symfony Finder deprecations)?

Integration Approach

Stack Fit

  • Laravel Ecosystem:

    • Symfony Finder: Already used in Laravel’s files() helper and Illuminate\Filesystem. Minimal friction.
    • Composer: Zero-config installation. No version conflicts with Laravel’s PHP 8.x support.
    • Artisan: Ideal for CLI tools (e.g., scan:classes, generate:api). Avoid runtime usage in boot().
    • Reflection: Compatible with Laravel’s ReflectionClass usage (e.g., in app()->make() or new ReflectionClass()).
  • Tooling Compatibility:

    • PHPUnit: Use in DataProvider traits or extensions to dynamically load test classes.
    • Laravel Mix/Vite: Generate static assets (e.g., API docs) from class metadata.
    • IDE Plugins: Feed class maps to VS Code/Laravel IDE Helper for smarter autocomplete.
  • Anti-Patterns:

    • Avoid Runtime Scans: Never use in boot() or register()—risk of slow boot times.
    • Avoid Autoloader Hacks: enableAutoloading() can break Laravel’s ClassLoader. Prefer cached scans.
    • Avoid AST Transformations: For modifying class bodies, pair with nikic/PHP-Parser.

Migration Path

Phase Action Tools/Libraries Risk
Evaluation Benchmark scan times and memory usage on a staging clone of the codebase. Blackfire, Laravel Debugbar Low
Pilot Build a proof-of-concept Artisan command (e.g., scan:unused-classes) to identify dead code. ClassIterator, FileCache Medium
Integration Register ClassIterator as a Laravel service and create a Facade for DSL access. AppServiceProvider, Illuminate\Support\Facades High (Reflection)
Optimization Cache scan results and run heavy operations asynchronously (e.g., Laravel Queues). Illuminate\Cache, Illuminate\Queue Low
Extension Add Laravel-specific filters (e.g., isServiceProvider(), isEventListener()). Custom Filter classes Medium

Compatibility

  • Laravel Versions:
    • Supported: Laravel 8+ (PHP 8.x). Test with Symfony Finder’s latest stable version.
    • Legacy: Laravel
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui