Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

使用 PHP Insights 在终端查看 PHP 项目代码质量

作者:平凡中的不凡   发布日期:2024-11-25   浏览:113

要使用 PHP Insights 在终端查看 PHP 项目代码质量,需要按照以下步骤进行操作:

  1. 安装 PHP Insights:在终端中运行以下命令安装 PHP Insights:
composer require nunomaduro/phpinsights --dev
  1. 运行 PHP Insights:在终端中运行以下命令来运行 PHP Insights:
vendor/bin/phpinsights

这将会显示与代码质量相关的各种信息,例如代码复杂度、命名约定、代码风格等。

  1. 自定义配置(可选):你可以在项目根目录下创建一个 .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项目

大家都在看

php session用法

phpisset函数

php后端

php爬虫框架

php读取csv文件

php 三元表达式

php文件加密

php 拆分字符串

php pcntl

php ||

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站