Skip to content

feat: EC-CUBE 4.4への対応#23

Open
KenTanaka wants to merge 1 commit into
EC-CUBE:mainfrom
KenTanaka:feat-4.4
Open

feat: EC-CUBE 4.4への対応#23
KenTanaka wants to merge 1 commit into
EC-CUBE:mainfrom
KenTanaka:feat-4.4

Conversation

@KenTanaka

@KenTanaka KenTanaka commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

概要

会員向けアプリ認証(TOTP)プラグインを EC-CUBE 4.4(Symfony 7.4 / Doctrine ORM 3.0 / PHP 8.2+) に対応させ、コードを TwoFactorAuthCustomerApp42TwoFactorAuthCustomerApp44 に改名します。親プラグイン依存も TwoFactorAuthCustomer42TwoFactorAuthCustomer44 に更新します。4.3 とは非互換(属性必須・ORM 3・PHP 8.2+)のため、新規 4.4 ブランチへの取り込みです。

参考: 4.3→4.4 マイグレーション手順 (doc #346) /

変更内容

1. EC-CUBE 4.4 対応(コア移行)

  • Annotations → PHP 属性: Controller の @Route/@Template#[Route]/#[Template]Sensio 依存除去)、EntityExtension の @EntityExtension#[EntityExtension]Eccube\Attribute\EntityExtension
  • 型宣言の明示: Entity カラム型(Types::STRING)、メソッド引数・戻り値型(createSecret(): string / verifyCode(...): bool 等)
  • AbstractPluginManager: enable/disable/uninstall ほか関連メソッドに : void
  • テンプレート参照: @TwoFactorAuthCustomerApp44/... およびページ登録パスを TwoFactorAuthCustomerApp44 に統一
  • 依存更新: composer requireec-cube/twofactorauthcustomer44 へ、code / version: 4.4.0TwoFactorAuthCustomerApp44 に統一
  • PHPUnit 11: phpunit.xml.dist<source>/<extensions> 形式へ、Tests/bootstrap.php を追加

2. 動作改善(初回APP認証)

  • 初回登録(/mypage/two_factor_auth/app/create)でセッション切れ等により秘密鍵が欠落した場合、鍵を再発行して入力画面を出し直すフォールバックを追加
  • チャレンジ時は秘密鍵・トークンの型チェックを追加してから verifyCode を実行

3. 静的解析・整形ツール

  • Resource/rector.php / Resource/.php-cs-fixer.dist.php を追加(.php 設定は本体の Plugin\: サービス検出で 500 を避けるため Resource/ 配下に配置)
  • rector / php-cs-fixer を適用し、CI で dry-run 検査できる構成にする

4. CI(.github/workflows/main.yml ほか)

  • マトリクスを EC-CUBE 4.4 / PHP 8.2–8.5 / MySQL8・PostgreSQL に更新、checkout@v4$GITHUB_OUTPUT
  • 親プラグイン TwoFactorAuthCustomer44 を checkout / archive し、mock-package-api + eccube:composer:require で依存解決のうえ有効化
  • --ignore-platform-req=ext-redis: Symfony 7.4 の symfony/cache が古い php-redis と衝突して本体 composer install が失敗するのを回避(redis は未使用)
  • phpunit 前に cache:warmup: 有効プラグインのルート確定のため warmup を実行(Tests がある場合のみ PHPUnit 実行)
  • static-analysis ジョブ: php-cs-fixer / rector を SQLite・PHP 8.5 の1構成で実行
  • release.yml: 配布パッケージから Resource/rector.php / Resource/.php-cs-fixer.dist.php を除外

テスト

  • EC-CUBE 4.4 環境で手動試験を実施(初回APP認証・チャレンジ、セッション切れ時のフォールバックを含む)
  • CI マトリクス: 4.4 × PHP 8.2/8.3/8.4/8.5 × MySQL8/PostgreSQL
  • 静的解析ジョブ: php-cs-fixer / rector dry-run
  • 配布パッケージ(release.yml 相当)から開発用ファイルが除外されることを確認

Summary by CodeRabbit

  • 新機能
    • EC-CUBE 4.4向けの会員向け二要素認証(TOTP)プラグインに対応しました。
    • 認証コードの生成・検証や顧客情報への認証設定を、EC-CUBE 4.4環境で利用できます。
  • 改善
    • 顧客編集画面への認証設定表示を更新しました。
    • プラグインの有効化・無効化・アンインストール処理を安定化しました。
  • ドキュメント
    • インストール要件、依存プラグイン、設定方法、対応ブランチをREADMEに追加しました。
  • 品質向上
    • 自動テスト、静的解析、コード整形の実行環境を更新しました。

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

EC-CUBE 4.4向けにプラグイン識別情報、名前空間、PHP属性、型宣言、プラグイン管理処理を更新しました。PHPUnit・Rector・PHP-CS-Fixer設定、CIの対応環境、静的解析ジョブ、リリース時の配布除外処理も追加・変更しています。

Changes

EC-CUBE 4.4移行

Layer / File(s) Summary
パッケージとアプリケーション契約
composer.json, README.md, Controller/..., Entity/..., Event.php, Form/...
Composer情報と依存先を4.4向けに変更し、実装の名前空間、ルーティング・テンプレート指定、Doctrine定義をPHP属性へ移行しました。各メソッドに戻り値・引数型を追加し、秘密情報のsetterを追加しています。
プラグインライフサイクル更新
PluginManager.php
ページ・Twig・設定の登録および削除処理をApp44向けに変更し、戻り値型、配列型、null判定を明示しました。
開発・テストツール設定
Resource/.php-cs-fixer.dist.php, Resource/rector.php, Tests/bootstrap.php, phpunit.xml.dist
PHP-CS-FixerとRectorの設定、Composerと.envを読み込むテストブートストラップ、PHPUnit 10系形式の設定を追加・更新しました。
CI/CD移行と静的解析
.github/workflows/main.yml, .github/workflows/release.yml
CI対象をEC-CUBE 4.4、PHP 8.2〜8.5、App44へ更新し、キャッシュ・テスト実行・静的解析ジョブを変更しました。リリース配布物から開発用設定を削除します。

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

  • EC-CUBE/ec-cube issue 6762 — Symfony 7.4、PHP 8.2〜8.5、PHP属性、Rector、PHPUnit対応を含むEC-CUBE 4.4移行要件と一致します。

Poem

ぴょんと跳ねたら App44、
属性の花が咲いたよ。
CIの月が照らす道、
Rectorも兎も駆け抜ける。
4.4へ、にんじん乾杯!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed EC-CUBE 4.4対応という変更内容を簡潔に表しており、差分の主旨と一致しています。
✨ 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.

@KenTanaka KenTanaka changed the title Symfony7適合 - 基本となる改修は Claudeで実施 + レビュー済み(試験は手動実行) feat: EC-CUBE 4.4への対応 Jul 15, 2026

@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.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
PluginManager.php (1)

154-161: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

$PageLayoutnull の場合の TypeError を防ぐため、削除前に null チェックを追加してください。

Doctrine ORM 3.x では EntityManager::remove() の引数に厳格な型宣言 (object $object) が追加されています。
対象のページレイアウトが運用中に変更または削除されていて findOneBynull を返した場合、そのまま $em->remove($PageLayout) に渡すと TypeError が発生し、プラグインの無効化やアンインストール処理が中断してしまいます。

🛠 提案する修正
             if ($Page !== null) {
                 $Layout = $em->getRepository(Layout::class)->find(Layout::DEFAULT_LAYOUT_UNDERLAYER_PAGE);
                 $PageLayout = $em->getRepository(PageLayout::class)->findOneBy(['Page' => $Page, 'Layout' => $Layout]);
 
-                $em->remove($PageLayout);
+                if ($PageLayout !== null) {
+                    $em->remove($PageLayout);
+                }
                 $em->remove($Page);
                 $em->flush();
             }
🤖 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 `@PluginManager.php` around lines 154 - 161, Before calling
EntityManager::remove() in the Page deletion block, check whether $PageLayout
returned by findOneBy() is non-null; remove it only when present, while always
removing $Page and flushing as currently done.
🤖 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 @.github/workflows/main.yml:
- Line 1:
ワークフロー全体の権限設定としてpermissionsを追加し、GITHUB_TOKENを読み取り専用に制限してください。CIで必要な権限のみを明示し、それ以外の権限は付与しない構成にします。
- Around line 166-168: Update the plugin test block in the workflow so a missing
app/Plugin/${PLUGIN_CODE}/Tests directory causes the CI job to fail instead of
silently skipping PHPUnit. Keep PHPUnit execution unchanged when the directory
exists, and make the missing-directory branch explicitly exit with a nonzero
status.
- Around line 210-213: Update the “Setup PHP” workflow step to pin
nanasess/setup-php to commit 3f36b116d024300a7df978629a2bad9afceb2be3 instead of
tracking master.

In `@Controller/TwoFactorAuthCustomerAppController.php`:
- Around line 170-176: Update verifyCode() so its authKey and token parameters
accept nullable strings, then handle null values before calling
$this->tfa->verifyCode(). Return false for missing inputs and invoke the
verifier only when both arguments are non-null.

---

Outside diff comments:
In `@PluginManager.php`:
- Around line 154-161: Before calling EntityManager::remove() in the Page
deletion block, check whether $PageLayout returned by findOneBy() is non-null;
remove it only when present, while always removing $Page and flushing as
currently done.
🪄 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: 1260bfa6-9678-4eb3-9ec8-93ce1b988942

📥 Commits

Reviewing files that changed from the base of the PR and between f54aabd and 43be229.

📒 Files selected for processing (14)
  • .github/workflows/main.yml
  • .github/workflows/release.yml
  • Controller/TwoFactorAuthCustomerAppController.php
  • Entity/CustomerTrait.php
  • Event.php
  • Form/Type/Extension/Admin/TwoFactorAuthCustomerTypeExtension.php
  • Form/Type/TwoFactorAuthAppTypeCustomer.php
  • PluginManager.php
  • README.md
  • Resource/.php-cs-fixer.dist.php
  • Resource/rector.php
  • Tests/bootstrap.php
  • composer.json
  • phpunit.xml.dist

@@ -1,4 +1,4 @@
name: CI for TwoFactorAuthCustomerApp42
name: CI for TwoFactorAuthCustomerApp44

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

GITHUB_TOKEN を読み取り専用に制限してください。

permissions がないため、トークン権限がリポジトリ・組織の既定値に依存します。このCIに必要な権限を明示してください。GitHubも最小権限の明示を推奨しています。 (docs.github.com)

修正案
 name: CI for TwoFactorAuthCustomerApp44
 
+permissions:
+  contents: read
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: CI for TwoFactorAuthCustomerApp44
name: CI for TwoFactorAuthCustomerApp44
permissions:
contents: read
🧰 Tools
🪛 zizmor (1.26.1)

[warning] 1-281: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block

(excessive-permissions)

🤖 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 @.github/workflows/main.yml at line 1,
ワークフロー全体の権限設定としてpermissionsを追加し、GITHUB_TOKENを読み取り専用に制限してください。CIで必要な権限のみを明示し、それ以外の権限は付与しない構成にします。

Source: Linters/SAST tools

Comment on lines +166 to +168
if [ -d "app/Plugin/${PLUGIN_CODE}/Tests" ]; then
./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

テストディレクトリがない場合もCIを失敗させてください。

現在はプラグインの配置不備やテスト欠落が発生しても、PHPUnitを一度も実行せず成功します。

修正案
-          if [ -d "app/Plugin/${PLUGIN_CODE}/Tests" ]; then
-            ./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests
-          fi
+          test -d "app/Plugin/${PLUGIN_CODE}/Tests"
+          ./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ -d "app/Plugin/${PLUGIN_CODE}/Tests" ]; then
./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests
fi
test -d "app/Plugin/${PLUGIN_CODE}/Tests"
./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests
🤖 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 @.github/workflows/main.yml around lines 166 - 168, Update the plugin test
block in the workflow so a missing app/Plugin/${PLUGIN_CODE}/Tests directory
causes the CI job to fail instead of silently skipping PHPUnit. Keep PHPUnit
execution unchanged when the directory exists, and make the missing-directory
branch explicitly exit with a nonzero status.

Comment on lines +210 to +213
- name: Setup PHP
uses: nanasess/setup-php@master
with:
php-version: '8.5'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 固定候補のSHAを取得し、内容を監査してから workflow に設定する
gh api repos/nanasess/setup-php/commits/master --jq '.sha'

Repository: EC-CUBE/TwoFactorAuthCustomerApp42

Length of output: 213


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow excerpt =="
sed -n '200,220p' .github/workflows/main.yml

echo
echo "== commit existence check =="
gh api repos/nanasess/setup-php/commits/3f36b116d024300a7df978629a2bad9afceb2be3 --jq '.sha'

Repository: EC-CUBE/TwoFactorAuthCustomerApp42

Length of output: 827


nanasess/setup-php3f36b116d024300a7df978629a2bad9afceb2be3 に固定してください。 master のままだと更新がそのまま CI に入ります。

🤖 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 @.github/workflows/main.yml around lines 210 - 213, Update the “Setup PHP”
workflow step to pin nanasess/setup-php to commit
3f36b116d024300a7df978629a2bad9afceb2be3 instead of tracking master.

Comment on lines 170 to 176
/**
* 認証コードを取得.
*
* @param string $authKey
* @param string $token
*
* @return boolean
* 認証コードを検証.
*/
private function verifyCode($authKey, $token)
private function verifyCode(string $authKey, string $token): bool
{
return $this->tfa->verifyCode($authKey, $token, 1);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

セッション消失等の予期せぬ状態での TypeError (500エラー)を防ぐため、引数に null を許容してください。

PHP 8 では型宣言が厳格であるため、string 型の引数に null を渡すと TypeError が発生してシステムエラーとなります。
フォームのCSRFトークン検証(isValid())によってセッション切れリクエストの多くは事前に弾かれますが、予期せぬ状態やイレギュラーなPOSTにおいて $auth_keynull のまま到達した場合にクラッシュするリスクがあります。引数に ?string を指定し、内部で安全に null チェックを行うことを推奨します。

🛠 提案する修正
-    private function verifyCode(string $authKey, string $token): bool
+    private function verifyCode(?string $authKey, ?string $token): bool
     {
+        if ($authKey === null || $token === null) {
+            return false;
+        }
         return $this->tfa->verifyCode($authKey, $token, 1);
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* 認証コードを取得.
*
* @param string $authKey
* @param string $token
*
* @return boolean
* 認証コードを検証.
*/
private function verifyCode($authKey, $token)
private function verifyCode(string $authKey, string $token): bool
{
return $this->tfa->verifyCode($authKey, $token, 1);
}
/**
* 認証コードを検証.
*/
private function verifyCode(?string $authKey, ?string $token): bool
{
if ($authKey === null || $token === null) {
return false;
}
return $this->tfa->verifyCode($authKey, $token, 1);
}
🤖 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 `@Controller/TwoFactorAuthCustomerAppController.php` around lines 170 - 176,
Update verifyCode() so its authKey and token parameters accept nullable strings,
then handle null values before calling $this->tfa->verifyCode(). Return false
for missing inputs and invoke the verifier only when both arguments are
non-null.

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.

1 participant