Laravel Stats

Jun 23, 2024 | Data Science

Get insights about your Laravel or Lumen Project.

Laravel Stats Badge Tests Badge Downloads Badge Buy us a tree

Laravel Stats Screenshot

Installing

The easiest way to install the package is by using composer. Open your terminal and run:

composer require wnx/laravel-stats --dev

The package will automatically register itself. If you’re using Lumen, you need to manually register the Service Provider in your bootstrap/app.php file:

php $app->register(WnxLaravelStats\StatsServiceProvider::class);

Optionally, you can publish the config file in your Laravel applications with the following command:

php artisan vendor:publish --provider=WnxLaravelStats\StatsServiceProvider

Usage

After installing, you can generate the statistics by running the following Artisan Command:

php artisan stats

Make sure you run php artisan config:clear before running the above command.

The statistics are also available as JSON:

php artisan stats --json

If you want a more detailed report and to see which classes have been grouped into which component, use the --verbose option:

php artisan stats --verbose

The verbose option is available for the JSON format as well:

php artisan stats --json --verbose

Understanding the Package’s Behavior

Imagine Laravel Stats like a diligent librarian attempting to organize various books on a shelf based on their categories. It scans through your Laravel project files, classified as books, utilizing specific criteria to group them. For instance:

  • Livewire Components: Think of them as special books that must be labeled with a unique tag.
  • Controllers: These are like books that must be checked against a library map (the Route).
  • Models: These books come with a defined structure (must extend Illuminate\Database\Eloquent\Model).
  • Jobs: Every job is like a book that follows specific rules written by the author (it must use the Dispatchable trait).

This way, just as a librarian organizes the books, Laravel Stats classifies your project’s components for clear insights.

Creating Custom Classifiers

If your application has unique components that you’d like reflected in Laravel Stats, you can create your own Classifiers. Here’s a snippet on how to do that:


isSubclassOf(App\Repositories\BaseRepository::class);
    }

    public function countsTowardsApplicationCode(): bool {
        return true;
    }

    public function countsTowardsTests(): bool {
        return false;
    }
}

Configure this classifier in your config/stats.php file under the custom_component_classifier:


custom_component_classifier = [
    App\Classifiers\RepositoryClassifier::class
],

Treeware

While you’re free to use this package, if it makes it to your production environment, you’re required to buy the world a tree! By supporting Treeware, you’re contributing to the planet by restoring wildlife habitats and creating employment for locals. Buy trees here.

Learn more about Treeware at treeware.earth.

Running Tests

The package contains tests written in PHPUnit. To run the tests, use the following command:

vendor/bin/phpunit

Troubleshooting

If you encounter any issues while using Laravel Stats, consider the following:

  • Make sure your Laravel version is compatible with the package.
  • Remember to clear the configuration cache with php artisan config:clear if you are experiencing issues with stats generation.
  • If you are using Pest PHP for writing tests, be aware that these files will be excluded from the statistics.
  • For unresolved queries, check the official documentation or the GitHub repository for discussions and troubleshooting tips.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

This package is a powerful tool for understanding the structure of your Laravel project. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox