Installation:
composer require "wnx/laravel-stats" --dev
The package auto-registers, so no additional steps are needed unless you want to customize behavior.
First Run:
php artisan config:clear && php artisan stats
This generates a human-readable report in the terminal, summarizing:
JSON Output (for programmatic use):
php artisan stats --json
Outputs structured data for integration with CI/CD pipelines or monitoring tools.
Run php artisan stats after a major refactor or before a release to:
UserController with 50+ methods).composer.json).CI/CD Integration:
phpunit.xml or GitHub Actions:
<php>
<env name="STATS_JSON" value="1"/>
</php>
Local Development:
.bashrc:
alias stats='php artisan stats'
git diff --name-only HEAD~1 HEAD | grep '\.php$' && stats
Custom Reports:
Wnx\LaravelStats\Commands\StatsCommand class to filter output (e.g., only show App\Http\Controllers):
protected function getReport(): Report
{
return parent::getReport()->filterByNamespace('App\Http\Controllers');
}
Laravel Forge/Envoyer:
stats.json file and compare across deployments:
php artisan stats --json > stats.json
diff to detect metric changes:
diff stats.json stats.previous.json
IDE Plugins:
Documentation:
CONTRIBUTING.md to guide new devs on project structure:
This project has 420 classes (avg. 15 methods/class). Aim for <20 cyclomatic complexity.
Performance:
vendor/ and node_modules/ from analysis by publishing the config:
'exclude' => [
'vendor/',
'node_modules/',
'tests/',
],
False Positives:
Illuminate\Support\Collection may inflate method counts. Ignore it in config:
'ignored_namespaces' => [
'Illuminate\Support\',
],
Dynamic Classes:
--skip-errors to continue:
php artisan stats --skip-errors
Verbose Output:
php artisan stats --verbose
Custom Parsers:
Wnx\LaravelStats\Parsers\ParserInterface to handle custom syntax (e.g., Blade templates):
class BladeParser implements ParserInterface
{
public function parse(string $file): array
{
// Custom logic for Blade files
}
}
Configuration Quirks:
config/laravel-stats.php is published if modifying defaults:
php artisan vendor:publish --tag=laravel-stats-config
php artisan config:clear
Add Custom Metrics:
Wnx\LaravelStats\Report to include domain-specific metrics (e.g., "API endpoint coverage"):
class CustomReport extends Report
{
public function calculateApiCoverage(): int
{
// Logic to count API routes vs. implemented controllers
}
}
Visualization:
jq '.metrics.methods | length' stats.json # Count methods
Git Hooks:
# .git/hooks/pre-commit
php artisan stats --json | jq '.metrics.complexity > 20' && exit 1
How can I help you explore Laravel packages today?