要使用 PHP Insights 在终端查看 PHP 项目代码质量,需要按照以下步骤进行操作:
composer require nunomaduro/phpinsights --dev
vendor/bin/phpinsights
这将会显示与代码质量相关的各种信息,例如代码复杂度、命名约定、代码风格等。
.phpinsights.php
文件来自定义 PHP Insights 的配置。例如,你可以修改规则、指定要忽略的文件或目录等。以下是一个简单的示例 .phpinsights.php
文件:
<?php
declare(strict_types=1);
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenSecurityIssues;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenTraits;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenFinalClasses;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenPrivateMethods;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineGlobalConstants;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineGlobalVariables;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenFinalMethods;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenPublicProperties;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenPublicMethods;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenComplexity;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenStaticMethods;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenPrivateProperties;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenTraitsVisibility;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenPrivateConstants;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenGlobalVariables;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenPublicConstants;
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenFunctions;
return [
'preset' => 'laravel',
'exclude' => [
'app/Http/Controllers/ExampleController.php',
],
'add' => [
ForbiddenSecurityIssues::class,
ForbiddenTraits::class,
ForbiddenNormalClasses::class,
ForbiddenFinalClasses::class,
ForbiddenPrivateMethods::class,
ForbiddenDefineGlobalConstants::class,
ForbiddenDefineGlobalVariables::class,
ForbiddenFinalMethods::class,
ForbiddenPublicProperties::class,
ForbiddenPublicMethods::class,
ForbiddenComplexity::class,
ForbiddenStaticMethods::class,
ForbiddenPrivateProperties::class,
ForbiddenTraitsVisibility::class,
ForbiddenPrivateConstants::class,
ForbiddenGlobalVariables::class,
ForbiddenPublicConstants::class,
ForbiddenFunctions::class,
],
];
这个示例配置文件使用了 Laravel 预设,并添加了一些自定义规则。你可以根据自己的需求进行修改。
通过以上步骤,你就可以在终端中使用 PHP Insights 来查看 PHP 项目的代码质量。
上一篇:php time_nanosleep() 函数延迟代码执行若干秒和纳秒。
下一篇:PHP创建laravel项目
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站