Get insights about your Laravel or Lumen Project.
The easiest way to install the package is by using composer.
composer require "wnx/laravel-stats" --dev
The package will automatically register itself.
If you're using Lumen you have to manually register the Service Provider in your bootstrap/app.php
file:
$app->register(WnxLaravelStatsStatsServiceProvider::class);
Optionally, you can publish the config file in your Laravel applications with the following command:
php artisan vendor:publish --provider="WnxLaravelStatsStatsServiceProvider"
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 see which classes have been grouped into which component, you can use the --verbose
-option.
php artisan stats --verbose
The verbose option is available for the JSON format also.
php artisan stats --json --verbose
Note If your project is using Pest PHP for writing tests, these files will automatically be excluded from the statistics. Due to how "laravel-stats" works internally, Pest PHP tests can't currently be detected. See #194 for more information.
The package scans the files defined in the paths
-array in the configuration file. It then applies Classifiers to those classes to determine which Laravel Component the class represents.
Component | Classification |
---|---|
Livewire Components | Must extend LivewireComponent |
Controller | Must be registered with a Route & does not extend LivewireComponent |
Model | Must extend IlluminateDatabaseEloquentModel |
Command | Must extend IlluminateConsoleCommand |
Rule | Must extend IlluminateContractsValidationRule |
Policy | The Policy must be registered in your AuthServiceProvider |
Middleware | The Middleware must be registered in your Http-Kernel |
Event | Must use IlluminateFoundationEventsDispatchable -Trait |
Event Listener | Must be registered for an Event in EventServiceProvider |
Must extend IlluminateMailMailable |
|
Notification | Must extend IlluminateNotificationsNotification |
Nova Action | Must extend LaravelNovaActionsAction |
Nova Dashboard | Must extend LaravelNovaDashboard |
Nova Filter | Must extend LaravelNovaFiltersFilter |
Nova Lens | Must extend LaravelNovaLensesLens |
Nova Resource | Must extend LaravelNovaResource |
Job | Must use IlluminateFoundationBusDispatchable -Trait |
Migration | Must extend IlluminateDatabaseMigrationsMigration |
Request | Must extend IlluminateFoundationHttpFormRequest |
Resource | Must extend IlluminateHttpResourcesJsonJsonResource or IlluminateHttpResourcesJsonResourceCollection |
Seeder | Must extend IlluminateDatabaseSeeder |
ServiceProvider | Must extend IlluminateSupportServiceProvider |
Blade Components | Must extend IlluminateViewComponent |
Custom Casts | Must implement IlluminateContractsDatabaseEloquentCastsAttributes or IlluminateContractsDatabaseEloquentCastsInboundAttributes |
Database Factory | Must extend IlluminateDatabaseEloquentFactory |
Dusk Tests | Must extend LaravelDuskTestCase |
BrowserKit Test | Must extend LaravelBrowserKitTestingTestCase |
PHPUnit Test | Must extend PHPUnitFrameworkTestCase |
If your application has it's own components you would like to see in laravel-stats
you can create your own "Classifiers".
Create your own Classifiers by implementing the Classifier
-contract and adding the class to the stats.custom_component_classifier
config array.
For example:
// app/Classifiers/RepositoryClassifier.php
<?php
namespace AppClassifiers;
use WnxLaravelStatsReflectionClass;
use WnxLaravelStatsContractsClassifier;
class RepositoryClassifier implements Classifier
{
public function name(): string
{
return 'Repositories';
}
public function satisfies(ReflectionClass $class): bool
{
return $class->isSubclassOf(AppRepositoriesBaseRepository::class);
}
public function countsTowardsApplicationCode(): bool
{
return true;
}
public function countsTowardsTests(): bool
{
return false;
}
}
// config/stats.php
<?php
...
'custom_component_classifier' => [
AppClassifiersRepositoryClassifier::class
],
...
You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.
It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you support this package and contribute to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
You can buy trees here offset.earth/treeware
Read more about Treeware at treeware.earth
The package has tests written in phpunit. You can run them with the following command.
./vendor/bin/phpunit
If you're working on the package locally and want to just run the command in a demo project you can use the composer path-repository format.
Add the following snippet to the composer.json
in your demo project.
{
"repositories": [
{
"type": "path",
"url": "/path/to/laravel-stats/",
"options": {
"symlink": true
}
}
],
}
And "install" the package with composer require wnx/laravel-stats
. The package should now be symlinked in your demo project.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE file for details.