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

Laravel Stats Laravel Package

danielbaylis/laravel-stats

Laravel package for collecting, storing, and querying application statistics in Laravel. Track events and counters, aggregate metrics over time, and retrieve reports via an easy API to monitor usage and performance in your app.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The danielbaylis/laravel-stats package provides code statistics (e.g., lines of code, complexity metrics) for Laravel projects, which aligns with developer productivity, maintainability tracking, and technical debt assessment. It is particularly useful for:
    • Internal tooling (e.g., CI/CD dashboards, onboarding docs).
    • Code quality monitoring (complementing tools like PHPStan, Psalm).
    • Historical trend analysis (e.g., tracking growth in a monorepo).
  • Non-Functional Fit:
    • Lightweight: Runs via CLI commands (php artisan stats:...), avoiding runtime overhead.
    • Extensible: Hooks into Laravel’s service container, allowing custom metric collectors.
    • Isolated: Operates on the filesystem/codebase, not database-dependent (unlike analytics packages).

Integration Feasibility

  • Laravel Compatibility:
    • Core Integration: Leverages Laravel’s Artisan commands and service container (v5.5+). Minimal boilerplate required.
    • Dependency Conflicts: Low risk—only requires PHP 7.4+ and Laravel 5.5+. No major framework dependencies.
  • Data Flow:
    • Input: Scans project directories (configurable via config/stats.php).
    • Output: Generates JSON/CSV reports or stores metrics in a database (if extended).
    • Output Consumption: Designed for human-readable reports or programmatic access (e.g., API endpoints).

Technical Risk

Risk Area Assessment Mitigation
Performance CLI scans may slow for large repos (>10k files). Schedule runs during off-peak hours; exclude vendor//node_modules/ via config.
Accuracy Metrics (e.g., cyclomatic complexity) may not match IDE tools (e.g., PhpStorm). Validate against known benchmarks; document limitations in reports.
Database Overhead If storing metrics in DB, could bloat storage for frequent runs. Use a separate DB table with TTL; aggregate historical data.
Customization Limited out-of-the-box metrics (e.g., no test coverage integration). Extend via StatsServiceProvider or fork for bespoke collectors.
Deprecation Low-maintenance package (no recent commits). Monitor GitHub issues; fork if abandoned.

Key Questions

  1. Use Case Clarity:

    • Is this for real-time monitoring (e.g., CI feedback) or periodic audits (e.g., quarterly reports)?
    • Will metrics be consumed by humans (reports) or machines (APIs/dashboards)?
  2. Data Storage:

    • Should metrics be stored in a database, filesystem, or external service (e.g., Elasticsearch)?
    • How will historical data be aggregated/archived to avoid bloat?
  3. Extensibility Needs:

    • Are additional metrics required (e.g., test coverage, dependency analysis)?
    • Should the package integrate with other tools (e.g., GitHub Actions, Slack alerts)?
  4. Scalability:

    • Will this run on multiple repositories (e.g., monorepo) or a single project?
    • Are there parallelization needs for large codebases?
  5. CI/CD Integration:

    • Should stats trigger alerts (e.g., "complexity increased by 20%")?
    • How will results be published (e.g., GitHub PR comments, internal wiki)?

Integration Approach

Stack Fit

  • Best For:
    • Laravel monorepos or large projects needing codebase visibility.
    • Teams using PHP-centric stacks (avoids polyglot complexity).
    • Environments where developer tooling is prioritized over runtime performance.
  • Less Ideal For:
    • Microservices architectures (stats per service may be overkill).
    • Non-PHP projects (would require wrapper scripts).
    • High-frequency runtime analytics (use a dedicated profiler instead).

Migration Path

  1. Pilot Phase:

    • Install via Composer:
      composer require danielbaylis/laravel-stats
      
    • Run basic commands to validate output:
      php artisan stats:collect
      php artisan stats:report
      
    • Compare metrics with manual counts (e.g., cloc) for accuracy.
  2. Configuration:

    • Customize config/stats.php to:
      • Exclude directories (e.g., tests/, storage/).
      • Adjust metric collectors (e.g., disable complexity if irrelevant).
    • Example:
      'directories' => [
          app_path(),
          resource_path('views'),
      ],
      'collectors' => [
          \DanielBaylis\Stats\Collectors\LinesOfCode::class,
          // \DanielBaylis\Stats\Collectors\Complexity::class, // Disable if needed
      ],
      
  3. Data Pipeline:

    • Option A: File-Based Reports
      • Use php artisan stats:report --format=json for programmatic access.
      • Parse JSON in a separate service (e.g., Python script) for dashboards.
    • Option B: Database Storage
      • Extend the package to store metrics in a table (e.g., code_stats):
        // In a custom Artisan command:
        $stats = Stats::collect();
        DB::table('code_stats')->insert([
            'metric' => 'loc',
            'value' => $stats->linesOfCode,
            'timestamp' => now(),
        ]);
        
    • Option C: External API
      • POST results to a dedicated analytics service (e.g., custom Laravel API).
  4. Automation:

    • Schedule via Laravel Scheduler (e.g., weekly):
      $schedule->command('stats:collect')->weekly();
      
    • Trigger in CI/CD (e.g., GitHub Actions):
      - name: Generate Code Stats
        run: php artisan stats:collect
      - name: Upload Report
        uses: actions/upload-artifact@v3
        with:
          name: code-stats
          path: storage/app/stats.json
      

Compatibility

  • Laravel Versions: Tested on 5.5+; may need minor tweaks for Lumen or Laravel 10.
  • PHP Extensions: None required (pure PHP).
  • Database: Only needed if extending for storage (supports MySQL, PostgreSQL, SQLite).
  • Third-Party Tools:
    • Git: Assumes stats are run post-commit (not real-time).
    • CI Tools: Works with GitHub Actions, GitLab CI, etc., via CLI.

Sequencing

  1. Phase 1: Validation (1–2 weeks)

    • Install, run manual tests, validate metrics.
    • Document discrepancies (e.g., "complexity differs from PhpStorm by X%").
  2. Phase 2: Integration (1–3 weeks)

    • Configure for target repositories.
    • Build data pipeline (file/DB/API).
    • Write basic consumers (e.g., CLI tool to display trends).
  3. Phase 3: Automation (1 week)

    • Schedule runs (CI/CD or Laravel Scheduler).
    • Set up alerts (e.g., Slack for spikes in complexity).
  4. Phase 4: Extension (Ongoing)

    • Add custom collectors (e.g., for test coverage via phpunit).
    • Integrate with dashboards (e.g., Grafana, custom Laravel admin panel).

Operational Impact

Maintenance

  • Package Updates:
    • Monitor for breaking changes (low risk; package is stable).
    • Fork if maintenance stalls (simple to extend).
  • Configuration Drift:
    • Document config/stats.php changes in README or wiki.
    • Use environment variables for critical paths (e.g., excluded directories).
  • Metric Schema:
    • If storing in DB, version the schema (e.g., code_stats_v1).

Support

  • Troubleshooting:
    • Common issues:
      • Permission errors: Ensure CLI user can read app/ and vendor/ (if needed).
      • Slow runs: Add --exclude flags or run during off-hours.
      • Metric discrepancies: Cross-validate with cloc or phpmd.
    • Debug with:
      php artisan stats:collect --verbose
      
  • Documentation:
    • Create internal docs for:
      • How to add custom metrics.
      • Interpreting reports (e.g., "high complexity = refactor candidate").
      • CI/CD setup (e.g
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
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