nunomaduro/phpinsights
PHP Insights is a terminal tool to analyze PHP code quality, style, architecture, and complexity. Works out of the box with Laravel (artisan insights), Symfony, Yii, Magento, and more, with built-in checks for reliability and loose coupling.
Start by installing the package via Composer (require-dev):
composer require nunomaduro/phpinsights --dev
Run it immediately with ./vendor/bin/phpinsights — no config needed. It scans app/, config/, routes/, and database/ by default, producing a summary score and breaking issues into categories: Architecture, Complexity, Distribution, Style, and Code (e.g., NestingLevel, CognitiveComplexity, UnusedCode). First use case: run before merging PRs or during local development to get instant feedback on newly added code.
v2.14.0 note: Fully supports Laravel 13 and Symfony 8, making it ideal for projects upgrading to latest major releases. PHP 8.5 is now supported (including new language features and deprecation changes), while support for PHP 8.1/8.2 has been dropped — ensure your CI/development environment uses PHP 8.3 or 8.5.
Integrate into your workflow using presets, CLI flags, and CI automation.
--preset=[laravel|symfony|wordpress] to adapt rules to framework conventions (e.g., --preset=laravel enforces service container best practices).phpinsights.php config file (generated on first run via ./vendor/bin/phpinsights --init), allowing team-specific tolerance for complexity or style violations.phpinsights --min-quality=80 --min-complexity=60 --min-architecture=70 to fail builds when thresholds drop below.--format=json or --format=checkstyle for integration with tools like SonarQube or GitHub Code Scanning.--debug flag during refactoring to trace exactly which rule triggered a comment (e.g., "CognitiveComplexity too high in App\Services\OrderProcessor::calculateTotal()").--preset=laravel — the preset now includes rules aligned with Laravel 13’s syntax and conventions (e.g., updated enum usage, new event listener patterns). Similarly, Symfony 8 features (e.g., improved attributes handling) are validated under --preset=symfony.--clear-cache if changes aren’t reflected.ForbiddenImplicitCatchBlock may flag try {} catch (\Exception $e) {} blocks — explicitly declare Throwable if handling both Error and Exception.phpinsights.php config overrides defaults, but CLI flags override the config — double-check order of precedence.--only=Architecture,Style to narrow scope.phpinsights.php's exclude array (not .phpinsightsignore) — the latter is not supported.PHP_CodeSniffer\Sniffs\Sniff and registering via phpinsights.php → settings → sniffs — but note this package is not PHPCS itself; custom rules must integrate via PHP Insights’ own sniff infrastructure.How can I help you explore Laravel packages today?