Skip to content

fix: Rector の Attribute 引数順序で非推奨 Sensio クラスのパラメータ名を使わない (#6540)#6884

Open
nanasess wants to merge 5 commits into
EC-CUBE:4.4from
nanasess:fix/6540-rector-attribute-arguments-order
Open

fix: Rector の Attribute 引数順序で非推奨 Sensio クラスのパラメータ名を使わない (#6540)#6884
nanasess wants to merge 5 commits into
EC-CUBE:4.4from
nanasess:fix/6540-rector-attribute-arguments-order

Conversation

@nanasess

@nanasess nanasess commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

概要(Overview・Refs Issue)

Closes #6540

カスタム Rector ルール AttributeArgumentsOrderRector が、@Template("...")
#[Template(data: '...')]誤った名前付き引数へ変換してしまう問題を修正します。

原因

  1. AnnotationToAttributeRector がアノテーションを Attribute へ変換した時点では、まだ
    use 文が Sensio\Bundle\FrameworkExtraBundle\Configuration\Template(非推奨)を指している。
  2. AttributeArgumentsOrderRector がリフレクションで Sensio の Template を調べ、第一パラメータ
    $data を読み取って data: を付与する。
  3. その後 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 の提案に準拠):

非推奨(Sensio) 新クラス
...\Configuration\Template Symfony\Bridge\Twig\Attribute\Template
...\Configuration\Cache Symfony\Component\HttpKernel\Attribute\Cache
...\Configuration\IsGranted Symfony\Component\Security\Http\Attribute\IsGranted
...\Configuration\Security Symfony\Component\Security\Http\Attribute\IsGranted

新クラスがオートロードできない場合は従来どおり ReflectionException で空配列を返してスキップするため、安全側にフォールバックします。

実装に関する補足(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(...)] 引数並べ替えが従来どおり動作する(リグレッションガード)
  • マッピングを無効化すると本テストが赤くなり、有効化で緑になることを確認(修正がテストで守られている)
vendor/bin/phpunit tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php
OK (2 tests)

マイナーバージョン互換性保持のための制限事項チェックリスト

  • 既存機能の仕様変更はありません(開発時のみ使う Rector ルールの修正)
  • フックポイントの呼び出しタイミングの変更はありません
  • フックポイントのパラメータの削除・データ型の変更はありません
  • twigファイルに渡しているパラメータの削除・データ型の変更はありません
  • Serviceクラスの公開関数の、引数の削除・データ型の変更はありません
  • 入出力ファイル(CSVなど)のフォーマット変更はありません

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • 属性引数の並び替えで、非推奨表記が混在するケースでも正しい形式として判定されるよう改善し、結果の安定性を高めました。
  • Tests
    • 属性引数の順序を検証するテストを追加しました。
    • テスト用フィクスチャ(Template/Routeの属性記法)を更新しました。
    • 環境差によるテスト失敗を防ぐための事前読み込みや、カバレッジ対象の調整を行いました。

本 PR は #6877 を最新の 4.4 から作り直したものです(#6877 はクローズ)。

nanasess and others added 2 commits July 3, 2026 14:03
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>
- 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>
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e6ec875a-1461-4ec3-a9bb-380b439436ad

📥 Commits

Reviewing files that changed from the base of the PR and between ce30d74 and 23c02b9.

📒 Files selected for processing (2)
  • .github/workflows/coverage.yml
  • tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php

📝 Walkthrough

Walkthrough

AttributeArgumentsOrderRector に非推奨クラスから新しい Attribute クラスへの対応表を追加し、反映前にクラス名を置換するよう変更しています。あわせて、専用テスト、fixture、Rector 設定、テスト bootstrap、coverage ワークフローの調整が追加されています。

Changes

非推奨クラスマッピング対応

Layer / File(s) Summary
非推奨クラスマッピングとリフレクション対象置換ロジック
src/Eccube/Rector/CodingStyle/AttributeArgumentsOrderRector.php
DEPRECATED_CLASS_MAPPING を追加し、getConstructorParameterOrder() で反映前にクラス名を置換するよう変更。
Rector テスト基盤と fixture 追加
tests/bootstrap.php, tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php, tests/Eccube/Tests/Rector/CodingStyle/config/configured_rule.php, tests/Eccube/Tests/Rector/CodingStyle/Fixture/*.php.inc, .github/workflows/coverage.yml
テスト用 Rector 設定と実行クラスを追加し、TemplateRoute の属性引数形式を検証する fixture、Php84 polyfill の事前読込、coverage 実行時の rector グループ除外を追加。

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ji-eunsoo

Poem

ぴょんと跳ねて名をたどり
data じゃなく template に着地
fixture も整い
うさぎのテストは晴れやかに 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning tests/bootstrap.php と coverage.yml の変更は #6540 の修正本体とは別のCI/テスト基盤対応で、要件外の変更が含まれています。 CI安定化の変更は別PRへ分離するか、#6540 に必要な最小限の修正とテストだけに絞ってください。
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 主要な修正内容である AttributeArgumentsOrderRector の Sensio 非推奨クラス名問題を具体的に示しており、簡潔です。
Linked Issues check ✅ Passed Template/Cache/IsGranted/Security の旧クラス→新属性クラスのマッピング追加と、Template の期待結果を含むテスト追加で #6540 の要件を満たしています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php (1)

29-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cache / IsGranted / Security マッピングのテストが不足しています。

DEPRECATED_CLASS_MAPPING には Template 以外に CacheIsGrantedSecurity の3クラスも定義されていますが、fixture は deprecated_template_attribute.php.inc のみで、これら3クラスの変換結果を検証するテストがありません。将来的なリグレッションを検知できるよう、それぞれに対応する fixture の追加をご検討ください。

🤖 Prompt for 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.

In `@tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php`
around lines 29 - 32, The AttributeArgumentsOrderRectorTest data provider only
covers the Template mapping, so add fixtures for the Cache, IsGranted, and
Security entries from DEPRECATED_CLASS_MAPPING and make provideData() pick them
up via yieldFilesFromDirectory. Use the existing test class and its Fixture
directory to add one fixture per class so the rector’s conversion behavior is
verified for all deprecated attribute mappings.
🤖 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.

Nitpick comments:
In `@tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php`:
- Around line 29-32: The AttributeArgumentsOrderRectorTest data provider only
covers the Template mapping, so add fixtures for the Cache, IsGranted, and
Security entries from DEPRECATED_CLASS_MAPPING and make provideData() pick them
up via yieldFilesFromDirectory. Use the existing test class and its Fixture
directory to add one fixture per class so the rector’s conversion behavior is
verified for all deprecated attribute mappings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: beb3b334-3287-4633-b47d-311082008690

📥 Commits

Reviewing files that changed from the base of the PR and between deebf0b and fc500cf.

📒 Files selected for processing (5)
  • src/Eccube/Rector/CodingStyle/AttributeArgumentsOrderRector.php
  • tests/Eccube/Tests/Rector/CodingStyle/AttributeArgumentsOrderRectorTest.php
  • tests/Eccube/Tests/Rector/CodingStyle/Fixture/deprecated_template_attribute.php.inc
  • tests/Eccube/Tests/Rector/CodingStyle/Fixture/route_attribute_order.php.inc
  • tests/Eccube/Tests/Rector/CodingStyle/config/configured_rule.php

nanasess and others added 3 commits July 3, 2026 15:53
テスト env では Symfony DebugClassLoader が有効で、kernel 起動後にグローバル関数
bcround() から Symfony\Polyfill\Php84\Php84 を遅延 autoload すると
Php84::bcround() が解決できず、PHP 8.2/8.3 で税計算(TaxRuleService::bcround)を通す
全テストが「Call to undefined method Php84::bcround()」で失敗していた
(bootstrap 時点や standalone では bcround は正常に動作する)。
tests/bootstrap.php で kernel 起動前に Php84 クラスを class_exists で事前ロードし回避する。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
AttributeArgumentsOrderRectorTest は Rector を実行するため rector 同梱の
nikic/php-parser を読み込む。pcov 有効のカバレッジ実行では本体の
nikic/php-parser と衝突し「Cannot redeclare class PhpParser\Node\Scalar\Float_」で
fatal になり、coverage1.xml が生成されず coverage / Upload coverage reports が
失敗していた。テストに #[Group('rector')] を付与し、coverage.yml の phpunit
実行に --exclude-group rector を追加して回避する。通常の unit-test では
引き続き実行される。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.32%. Comparing base (a387a99) to head (23c02b9).

Files with missing lines Patch % Lines
...ctor/CodingStyle/AttributeArgumentsOrderRector.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              4.4    #6884   +/-   ##
=======================================
  Coverage   75.32%   75.32%           
=======================================
  Files         519      519           
  Lines       25483    25484    +1     
=======================================
+ Hits        19196    19197    +1     
  Misses       6287     6287           
Flag Coverage Δ
Unit 75.32% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[4.3-symfony7] AttributeArgumentsOrderRector で非推奨クラスのパラメータ名が使われる問題

2 participants