-
Notifications
You must be signed in to change notification settings - Fork 719
Expand file tree
/
Copy pathrector.php
More file actions
144 lines (138 loc) · 8.84 KB
/
Copy pathrector.php
File metadata and controls
144 lines (138 loc) · 8.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Eccube\Rector\CodingStyle\AttributeArgumentsOrderRector;
use Eccube\Rector\CodingStyle\NormalizePhpDocArrayGenericSpacingRector;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\Doctrine\Bundle210\Rector\Class_\EventSubscriberInterfaceToAttributeRector;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\CodeQuality\Rector\Class_\ControllerMethodInjectionToConstructorRector;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Symfony\Symfony34\Rector\Closure\ContainerGetNameToTypeInTestsRector;
use Rector\Symfony\Symfony61\Rector\Class_\CommandConfigureToAttributeRector;
use Rector\Symfony\Symfony61\Rector\Class_\CommandPropertyToAttributeRector;
use Rector\ValueObject\PhpVersion;
// この設定ファイルは Rector の CLI 実行専用。
// 公開ディレクトリに配置された場合に Web 経由で実行されないようガードする。
if (PHP_SAPI !== 'cli') {
http_response_code(403);
exit;
}
return RectorConfig::configure()
// EC-CUBEのPHPバージョンに合わせて設定
->withPhpVersion(PhpVersion::PHP_83)
// Rectorが解析するパスを指定
->withPaths([
__DIR__.'/src',
// __DIR__ . '/app',
__DIR__.'/tests',
__DIR__.'/codeception',
// プラグインディレクトリ等、個別案件の場合は必要に応じて追加
// __DIR__ . '/app/Plugin',
])
// スキップするパスやルールを指定
->withSkip([
// 特定のファイルやディレクトリを除外する場合
__DIR__ . '/rector',
// Codeception 自動生成ファイル (codecept build で再生成されるため Rector の指摘は意味なし)
__DIR__ . '/codeception/_support/_generated',
// 特定のルールを除外する場合
// 親の $entityManager 再宣言と step5 の接続専用 EM の取り違えを防ぐため
ControllerMethodInjectionToConstructorRector::class => [
__DIR__.'/src/Eccube/Controller/Install/InstallController.php',
],
// Codeception の grabMultiple() 等は戻り値の要素が null になり得るため、
// NullToStrictStringFuncCallArgRector が追加する (string) キャストを
// RecastingRemovalRector が除去しないようにスキップする
// (ローカル/CI 間でのルール適用揺らぎ対策)
RecastingRemovalRector::class => [
__DIR__.'/codeception/_support/Page/Admin/CustomerManagePage.php',
__DIR__.'/codeception/_support/Page/Admin/OrderManagePage.php',
__DIR__.'/codeception/acceptance/EF06OtherCest.php',
// scandir() / explode() の戻り値要素はバージョンによって string と推論されたり
// されなかったりし、 キャストを外すと NullToStrictStringFuncCallArgRector が
// 付け直す往復になるため、 こちらもキャストを維持する
__DIR__.'/codeception/_support/Helper/Acceptance.php',
__DIR__.'/src/Eccube/Service/Composer/OutputParser.php',
],
// ContainerGetNameToTypeInTestsRector は $container->get('service.id') の文字列サービスIDを
// get(Type::class) へ変換する。クラス名のエイリアスを持たない private サービス
// (例: 'doctrine.debug_data_holder', 'event_dispatcher', 'twig', 'session.factory') では
// ServiceNotFoundException になるため, それらはサービスIDを変数へ代入して get($serviceId) の
// 形にし変換対象から外すこと (ルールは無効化せず変数経由で回避する)。
// 既存例: AbstractWebTestCase / MailServiceTest / CartServiceTest / TwigExtensionPass
//
// shopping/order の各購入フローは同じ PurchaseFlow 型の別サービスであり、
// 型解決(get(PurchaseFlow::class))に置き換えると両者の区別が失われテストが無意味化する
ContainerGetNameToTypeInTestsRector::class => [
__DIR__.'/tests/Eccube/Tests/Service/PurchaseFlow/OrderMemoFlowTest.php',
// private / チャネル別ロガー ('security.firewall.map' / 'monolog.logger.mcp') も
// 型でなく文字列 ID で取得するため FQCN 変換を除外する
__DIR__.'/tests/Eccube/Tests/Service/Mcp/Contract/Api44LifecycleContractTest.php',
__DIR__.'/tests/Eccube/Tests/Service/Mcp/Contract/McpAuditLogIsolationContractTest.php',
],
// 8.3以上で対応可能
AddTypeToConstRector::class, // [BC]定数に型を追加する PHP 8.3 以降で有効
RenameMethodRector::class, //addがaddCommandに変換されてしまうため一旦スキップ
// EccubeCliToolCommand の description は runtime (ツールの description) で組み立てるため、
// #[AsCommand(description:)] へ移せない (属性は定数式のみ)。 このルールをスキップする。
CommandConfigureToAttributeRector::class => [
__DIR__.'/src/Eccube/Command/EccubeCliToolCommand.php',
],
])
// 個別にルールを追加する場合はここに記述
->withRules([
CommandConfigureToAttributeRector::class, // Symfonyコマンドのconfigureメソッドをアトリビュートに変換する
CommandPropertyToAttributeRector::class, // Symfonyコマンドのプロパティをアトリビュートに変換する,
StaticDataProviderClassMethodRector::class, // PHPUnitのデータプロバイダを静的メソッドに変換する
EventSubscriberInterfaceToAttributeRector::class, // Doctrine EventSubscriberをAsDoctrineListenerアトリビュートに変換する
AttributeArgumentsOrderRector::class, // すべての Attribute の引数をコンストラクタ引数順序に統一する
NormalizePhpDocArrayGenericSpacingRector::class, // PHPDoc の配列ジェネリクス表記のカンマ後のスペースを統一する
])
// よく使われるルールセットを有効化
->withSets([
SetList::DEAD_CODE,
LevelSetList::UP_TO_PHP_84, // PHPバージョンに合わせる
SymfonySetList::SYMFONY_74, // Symfonyのバージョンに合わせる (EC-CUBEのバージョンによって調整が必要)
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
DoctrineSetList::DOCTRINE_CODE_QUALITY,
DoctrineSetList::DOCTRINE_DBAL_30, // Doctrine DBALのバージョンに合わせる
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, // Doctrine Annotations を Attributes に変換
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_110, // PHPUnitのバージョンに合わせる
])
// Symfony のコンテナ XML(EC-CUBE の構成に合わせて調整が必要な場合があります)
->withSymfonyContainerXml(__DIR__.'/var/cache/dev/Eccube_KernelDevDebugContainer.xml')
// オプション: キャッシュ設定 (パフォーマンス向上のために推奨)
->withCache(
cacheClass: FileCacheStorage::class,
cacheDirectory: './var/rector_cache'
)
// オプション: import文の整理
->withImportNames(
importShortClasses: false,
importDocBlockNames: true,
importNames: true
)
// アノテーション→アトリビュートの変更
->withAttributesSets()
// オプション: Rectorの実行をパラレルで行う (パフォーマンス向上)
->withParallel();