nunomaduro/phpinsights
PHP Insights analyzes PHP code quality, style, architecture, and complexity from your terminal. Works out of the box with Laravel (artisan insights), Symfony, Yii, Magento, and more, with built-in checks for reliability and loose coupling.
phpinsights is a static analysis tool designed to integrate seamlessly with PHP projects, particularly Laravel. It leverages PHP_CodeSniffer, PHP-CS-Fixer, and custom insights to enforce code quality, architecture, and complexity standards.InsightsServiceProvider) that excludes Laravel-specific directories (e.g., config, storage, database) and tailors checks (e.g., disallowing dd() usage).composer require nunomaduro/phpinsights --dev) and runs via CLI (php artisan insights for Laravel). No runtime overhead.phpinsights.php) allows fine-grained control over excluded files, added/removed insights, and custom rules.dd()) may conflict with team conventions, requiring configuration overrides.phpinsights be gated in PRs (e.g., fail builds on critical violations)?php artisan insights (publishes config, uses Laravel’s service provider)../vendor/bin/phpinsights with generic presets (e.g., default, symfony).SlevomatCodingStandard).composer require nunomaduro/phpinsights --dev
php artisan vendor:publish --provider="NunoMaduro\PhpInsights\Application\Adapters\Laravel\InsightsServiceProvider"
phpinsights.php (e.g., exclude tests/, add custom insights).return [
'preset' => 'laravel',
'exclude' => ['tests/', 'legacy/'],
'add' => [
\NunoMaduro\PhpInsights\Domain\Metrics\Code\Comments::class => [
\SlevomatCodingStandard\Sniffs\Namespaces\FullyQualifiedClassNameInAnnotationSniff::class,
],
],
];
ide key in phpinsights.php (e.g., 'ide' => 'vscode').composer.json constraints).laravel-pint) are used.- name: Run PHP Insights
run: php artisan insights --min-quality=80 --no-interaction
--min-quality=50).phpinsights.php files (e.g., per repo) may lead to inconsistent setups.@phpcsSuppress).legacy/, vendor/) to reduce analysis scope.phpinsights.php template) can standardize rules.composer install --optimize-autoloader) to speed up builds.| Failure Mode | Impact | Mitigation |
|---|---|---|
| Strict rules block PRs | Devs cannot merge without fixes. | Start with --min-quality=50, gradually increase. |
| IDE hyperlinks broken | No file navigation in terminal. | Document fallback (e.g., grep + sed). |
| Analysis hangs on large files | CI/CD timeouts. | Exclude heavy files (e.g., migrations/). |
| Dependency conflicts | Toolchain breaks. | Use platform-check in composer.json. |
| False positives | Legitimate code flagged as bad. | Use @phpcsSuppress or override rules. |
php artisan insights and review top violations.--min-quality, --exclude, --format=json).dd() disallowance).How can I help you explore Laravel packages today?