該軟件包通過為您的Laravel項目或任何PHP應用程序運行RectorPHP的任務擴展了GrumPHP。
請注意,我們添加了--dry-run選項,因此源代碼從未更改。
安裝此軟件包的最簡單方法是通過作曲家:
composer require --dev palpalani/grumphp-rector-task
將擴展裝載機添加到您的grumphp.yml或grumphp.yml.dist中。該任務生活在rector名稱空間下,並具有以下可配置參數:
# grumphp.yml
grumphp :
tasks :
rector :
whitelist_patterns : []
config : ' rector.php '
triggered_by : ['php']
clear-cache : false
ignore_patterns : []
no-progress-bar : false
files_on_pre_commit : false
paths : []
no_diffs : false
extensions :
- palPalaniGrumPhpRectorTaskExtensionLoader默認情況下,這不會更新您的代碼,您需要手動進行。
Default: []
如果您只想在特定目錄上運行,請使用此選項指定。
Default: 'rector.php'
如果要使用與默認rector.php不同的配置文件,則可以使用此選項指定自定義配置文件位置。
Default: [php]
此選項將指定哪些文件擴展名將觸發此任務。
Default: false
清除已檢查文件的緩存。
Default: false
隱藏進度欄。有用的CI輸出。
Default: false
此選項使得在預設期間將更改的文件用作路徑是可能的。它將使用“路徑”選項來確保僅匹配路徑的固定文件經過驗證。
Default: false
在您的項目root中創建rector.php ,並如下配置。此示例文件IAM用於我的Laravel項目,但是您可以將庫與任何PHP項目一起使用。另外,您無需設置所有這些設置,請根據您的要求添加或刪除。
<?php
declare (strict_types= 1 );
use Rector Core Configuration Option ;
use Rector Set ValueObject SetList ;
use Rector CodeQuality Rector If_ SimplifyIfReturnBoolRector ;
use Rector Config RectorConfig ;
use Rector Php74 Rector Property TypedPropertyRector ;
use Rector CodeQuality Rector Isset_ IssetOnPropertyObjectToPropertyExistsRector ;
return static function ( RectorConfig $ rectorConfig ): void {
$ rectorConfig -> parallel ();
$ rectorConfig -> paths ([
__DIR__ . ' /app ' ,
__DIR__ . ' /config ' ,
__DIR__ . ' /database ' ,
__DIR__ . ' /tests '
__DIR__ . ' /routes ' ,
]);
$ rectorConfig -> skip ([
IssetOnPropertyObjectToPropertyExistsRector::class,
__DIR__ . ' /app/Http/Middleware/* ' ,
]);
$ rectorConfig -> rules ([
ReturnTypeFromStrictBoolReturnExprRector::class,
//ReturnTypeFromStrictNativeFuncCallRector::class,
ReturnTypeFromStrictNewArrayRector::class,
ReturnTypeFromStrictScalarReturnExprRector::class,
ReturnTypeFromReturnNewRector::class,
]);
$ rectorConfig -> sets ([
SetList:: CODE_QUALITY ,
SetList:: CODING_STYLE ,
SetList:: DEAD_CODE ,
SetList:: TYPE_DECLARATION ,
SetList:: EARLY_RETURN ,
SetList:: PHP_81 ,
LevelSetList:: UP_TO_PHP_80 ,
]);
$ rectorConfig -> sets ([
LaravelSetList:: LARAVEL_CODE_QUALITY ,
LaravelSetList:: LARAVEL_90 ,
LaravelLevelSetList:: UP_TO_LARAVEL_80 ,
]);
};請訪問RectorPHP以獲取更多配置示例。
如果要卸載此擴展程序,請首先刪除配置文件:從應用程序中的rector.php 。
然後刪除軟件包:
composer remove palpalani/grumphp-rector-task
有關最近發生了變化的更多信息,請參見ChangElog。
請有關詳細信息,請參閱貢獻。
請查看我們有關如何報告安全漏洞的安全政策。
我們使用SEMVER進行版本控制。有關可用的版本,請參見此存儲庫上的標籤。
麻省理工學院許可證(麻省理工學院)。請參閱許可證文件以獲取更多信息。