fix: Rector の Attribute 引数順序で非推奨 Sensio クラスのパラメータ名を使わない (#6540)#6877
fix: Rector の Attribute 引数順序で非推奨 Sensio クラスのパラメータ名を使わない (#6540)#6877nanasess wants to merge 5 commits into
Conversation
AnnotationToAttributeRector が Sensio FrameworkExtraBundle のアノテーションを Attribute 化した直後、まだ use 文が Sensio クラスを指す段階で AttributeArgumentsOrderRector が走ると、リフレクションが Sensio 側の コンストラクタ第一パラメータ(Template の $data 等)を読み取り、後段の RenameClassRector でクラスだけ置換されても誤った名前付き引数 (#[Template(data: '...')])が残っていた。Symfony Bridge の Template には data 引数が存在しないため、これは実害(Unknown named parameter)になる。 リフレクション対象のクラス名を新しい Attribute クラスへ事前に差し替える DEPRECATED_CLASS_MAPPING を追加し、置換後クラスの正しいパラメータ順序 (Template の $template 等)を使うようにした。出力される Attribute 名ノードには 手を加えない。 テスト(AttributeArgumentsOrderRectorTest)を追加し、Sensio Template の @template が #[Template(template: '...')] へ変換されること、および通常の Route 引数並べ替えが従来どおり動作することを検証。 Refs EC-CUBE#6540 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough
ChangesAttributeArgumentsOrderRector 非推奨クラスマッピング修正とテスト追加
Composerキャッシュ設定の更新
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php`:
- Around line 1-12: The test file header order is inconsistent with the
convention used under tests/, so add declare(strict_types=1); immediately after
the opening PHP tag and before the EC-CUBE license comment block. Update the
top-of-file bootstrap in AttributeArgumentsOrderRectorTest so it follows the
standard <?php → declare(strict_types=1); → license header sequence used by
other test classes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f9c6be38-c142-4ba0-b645-943ad12f530b
📒 Files selected for processing (5)
src/Eccube/Rector/CodingStyle/AttributeArgumentsOrderRector.phptests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.phptests/Eccube/Tests/Rector/CodingStyle/Fixture/deprecated_template_attribute.php.inctests/Eccube/Tests/Rector/CodingStyle/Fixture/route_attribute_order.php.inctests/Eccube/Tests/Rector/CodingStyle/config/configured_rule.php
- DEPRECATED_CLASS_MAPPING の @var を array<string, class-string> に修正 (キーは削除済み Sensio クラスの文字列リテラルで class-string 判定不可) - Rector テストの @dataProvider を #[DataProvider] 属性へ移行し declare(strict_types=1) を付与 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
5eb82d8 to
3d95cce
Compare
163ee69 to
606c520
Compare
composer アクションは vendor/ を prefix restore-keys でキャッシュしていたため、 別の composer.lock で作られた vendor/ が復元され、composer install が 「Nothing to install」で古い・不整合な vendor をそのまま使う状態が発生していた。 その結果、PHP 8.2/8.3 で polyfill-php84 の Php84::bcround() が未解決となり (Php84.php が古い版のまま bootstrap.php だけ新しい等の混在)、税計算(bcround)を 通る全テストが 600 件エラーになっていた。lock を変えてもキーが変わるだけで restore-keys が別 vendor を引き continue するため解消できなかった。 ステップ名(Get Composer Cache Directory)本来の意図どおり、キャッシュ対象を composer のダウンロードキャッシュ(composer config cache-files-dir)へ変更。 vendor/ は毎回 composer install でクリーンに構築されるため不整合が根絶される。 キー接頭辞も composer- → composer-cache- に変え、旧 vendor キャッシュを引かない。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
polyfill-php84 1.37.0 は PHP 8.2/8.3 で bootstrap80.php 経由の bcround() が Php84::bcround() 未解決になる壊れた実装で、fresh install でも 「Call to undefined method Symfony\Polyfill\Php84\Php84::bcround()」で 税計算(bcround)を通る全テストが失敗する(CI の fresh install で実証)。 4.4 本体が緑なのは古い working キャッシュで延命しているだけの潜在バグ。 1.38.1 は bootstrap80.php を廃し PHP>=8.2 を bootstrap82.php に振り分け bcround を正しく提供する。4.4 が既に php85=1.38.1 なのに php84 だけ 1.37.0 で 取り残されていた不整合の是正でもある(PHP 8.3 で bcround 動作を確認済み)。 先行の composer アクション修正(fresh install 化)と併せて根絶する。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
最新の |
概要(Overview・Refs Issue)
Closes #6540
カスタム Rector ルール
AttributeArgumentsOrderRectorが、@Template("...")を#[Template(data: '...')]と誤った名前付き引数へ変換してしまう問題を修正します。原因
AnnotationToAttributeRectorがアノテーションを Attribute へ変換した時点では、まだuse 文が
Sensio\Bundle\FrameworkExtraBundle\Configuration\Template(非推奨)を指している。AttributeArgumentsOrderRectorがリフレクションで Sensio のTemplateを調べ、第一パラメータ$dataを読み取ってdata:を付与する。RenameClassRectorが use 文をSymfony\Bridge\Twig\Attribute\Templateへ rename するが、名前付き引数
data:はそのまま残る。Symfony\Bridge\Twig\Attribute\Templateの第一パラメータは$templateで$dataは存在しないため、#[Template(data: '...')]は実行時に Unknown named parameter $data となる実害があります。方針(Policy)
AttributeArgumentsOrderRectorに「非推奨クラス → 新しい Attribute クラス」のマッピング(
DEPRECATED_CLASS_MAPPING)を追加し、リフレクション対象のクラス名を新クラスへ事前差し替えします。これにより置換後クラスの正しいパラメータ順序(
Templateの$template等)が使われます。差し替えるのはリフレクション対象のみで、出力される Attribute 名ノードには手を加えません。
対象マッピング(#6540 の提案に準拠):
...\Configuration\TemplateSymfony\Bridge\Twig\Attribute\Template...\Configuration\CacheSymfony\Component\HttpKernel\Attribute\Cache...\Configuration\IsGrantedSymfony\Component\Security\Http\Attribute\IsGranted...\Configuration\SecuritySymfony\Component\Security\Http\Attribute\IsGranted実装に関する補足(Appendix)
src/Eccube/Rector/CodingStyle/AttributeArgumentsOrderRector.php:DEPRECATED_CLASS_MAPPING定数を追加し、getConstructorParameterOrder()のリフレクション前にクラス名を差し替え。tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php(+ config / Fixture)を追加。テスト(Test)
AbstractRectorTestCaseベースのルール単体テストを追加し、ローカルで確認済み:use Sensio\...\Template;配下の#[Template('@admin/Content/cache.twig')]が#[Template(template: '@admin/Content/cache.twig')]へ変換される(修正の本丸)#[Route(...)]引数並べ替えが従来どおり動作する(リグレッションガード)マイナーバージョン互換性保持のための制限事項チェックリスト
🤖 Generated with Claude Code
Summary by CodeRabbit