airlst/rector-config

AirLST项目的Rector配置

4.3.8 2024-09-13 07:38 UTC

This package is auto-updated.

Last update: 2024-09-13 07:38:57 UTC


README

Latest Version on Packagist Total Downloads

AirLST项目的Rector配置。

安装

您可以通过Composer安装此包

composer require --dev airlst/rector-config

用法

在项目的根目录中创建一个rector.php文件,包含以下内容

<?php

declare(strict_types=1);

$factory = new Airlst\RectorConfig\Factory(['src']);

return $factory->create();

Factory类的构造函数接受一个数组,其中包含要扫描并修复的PHP文件路径。您可以传递任意数量的路径给它。

此方法返回一个Rector\Configuration\RectorConfigBuilder实例,可以进行进一步配置。例如,您可以指示Rector使用文件缓存

<?php

declare(strict_types=1);

$factory = new Airlst\RectorConfig\Factory(['src']);

return $factory
    ->create()
    ->withCache('cache/rector');

使用Laravel规则

您可以在调用create()之前通过链式调用withLaravelRules()方法来使用预定义的Laravel规则

<?php

declare(strict_types=1);

$factory = new Airlst\RectorConfig\Factory(['src']);

return $factory
    ->withLaravelRules()
    ->create();

运行Rector

使用以下命令运行Rector

./vendor/bin/rector

跳过规则

您可以在调用create()之前通过链式调用withSkip()方法来跳过某些规则

<?php

declare(strict_types=1);

$factory = new Airlst\RectorConfig\Factory(['src']);

return $factory
    ->withSkip([
        Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector::class,
    ])
    ->create();

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件