nunomaduro / phpinsights
- четверг, 16 мая 2019 г. в 00:17:57
PHP
💡 Instant PHP quality checks from your console
PHP Insights was created by, and is maintained by Nuno Maduro, and is the perfect starting point to analyze the code quality of your PHP projects. Carefully crafted to simplify the analysis of your code directly from your terminal.
Requires:
First, install PHP Insights via the Composer package manager:
composer require nunomaduro/phpinsights --devThen, use the phpinsights binary:
php ./vendor/bin/phpinsightsFirst, you should publish the config-file with:
php artisan vendor:publish --provider="NunoMaduro\PhpInsights\Application\Adapters\Laravel\InsightsServiceProvider"Then, use the insights Artisan command:
php artisan insightsFirst, you should create the config-file with:
cp vendor/nunomaduro/phpinsights/stubs/symfony.php phpinsights.phpThen, use the phpinsights binary:
php ./vendor/bin/phpinsightsInsightsYou may customize insights creating and editing the configuration file:
cp vendor/nunomaduro/phpinsights/stubs/config.php phpinsights.phpPHP Insights console command have different verbosity levels, which determine the quantity of issues displayed. By default, commands display only the 3 first issues per Insight, but you can display them all with the -v option:
php ./vendor/bin/phpinsights -vThe project is under development. As such, any help is welcome!
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 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,
],
],
],
];
}
}At the moment, this package doesn't have any test. Would you like to contribute? This is the perfect task.
Thank you to all the people who have already contributed to PHP Insights!
Nuno Maduro | Caneco | Quynh Xuan Nguyen | Mike Erickson | Viktor Szépe | Owen Voke |
PHP Insights is open-sourced software licensed under the MIT license.