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.
The project is under development. As such, any help is welcome!
[[TOC]]
InsightImagine that you want to create a new Insight that doesn't allow the usage of final classes:
src/Domain/Insights with the content:final class ForbiddenFinalClasses extends Insight
{
public function hasIssue(): bool
{
return (bool) count($this->collector->getConcreteFinalClasses());
}
public function getTitle(): string
{
return 'The use of `final` classes is prohibited';
}
}
Insight to a specific Metric inside src/Domain/Metrics:final class Classes implements HasInsights
{
// ...
public function getInsights(): array
{
return [
ForbiddenFinalClasses::class,
];
}
}
Are you aware of a PHPCS sniff that you would like to add to PHP Insights? You can add it in the following way:
final class Classes implements HasInsights
{
// ...
public function getInsights(): array
{
return [
UnusedPropertySniff::class,
];
}
}
Would you like to exclude a directory or remove an Insight for your favorite framework? You can add it in the following way:
In this example we are going to use the Laravel Framework.
src/Application/Adapters/Laravel/Preset.php and update the config file:final class Preset implements PresetContract
{
public static function getName(): string
{
return 'laravel';
}
public static function get(): array
{
return [
'exclude' => [
'config',
'storage',
'resources',
'bootstrap',
'nova',
'database',
'server.php',
'_ide_helper.php',
'_ide_helper_models.php',
'public',
],
'add' => [
Classes::class => [
ForbiddenFinalClasses::class,
],
],
'remove' => [
AlphabeticallySortedUsesSniff::class,
DeclareStrictTypesSniff::class,
DisallowMixedTypeHintSniff::class,
ForbiddenDefineFunctions::class,
ForbiddenNormalClasses::class,
ForbiddenTraits::class,
TypeHintDeclarationSniff::class,
],
'config' => [
ForbiddenPrivateMethods::class => [
'title' => 'The usage of private methods is not idiomatic in Laravel.',
],
ForbiddenDefineGlobalConstants::class => [
'ignore' => ['LARAVEL_START'],
],
ForbiddenFunctionsSniff::class => [
'forbiddenFunctions' => [
'dd' => null,
'dump' => null,
],
],
],
];
}
}
FormatterThe package has support for formatting the result.
All formats implement the contract src/Application/Console/Contracts/Formatter.
You are welcome to contribute with new formats or improve on the ones we already have.
How can I help you explore Laravel packages today?