Skip to content

refactor(entity): DateTime および Collection プロパティにネイティブ型宣言を追加 - #6569

Merged
nanasess merged 12 commits into
EC-CUBE:4.4from
nanasess:refactor/entity-type-declarations
Jul 27, 2026
Merged

refactor(entity): DateTime および Collection プロパティにネイティブ型宣言を追加#6569
nanasess merged 12 commits into
EC-CUBE:4.4from
nanasess:refactor/entity-type-declarations

Conversation

@nanasess

@nanasess nanasess commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

概要

Entityファイルの DateTime および Collection プロパティにPHP 8のネイティブ型宣言を追加しました。

変更内容

  • 全ての日付プロパティに nullable DateTime 型宣言 (?\DateTime $property = null) を追加
  • Collection 型宣言を追加(PHPDoc のジェネリクス情報は型推論のため維持)
  • DateTime プロパティの冗長な PHPDoc @var アノテーションを削除

対象ファイル(34ファイル)

主要Entity

  • Order.php, Customer.php, Product.php, Shipping.php, Cart.php

関連Entity

  • ProductClass.php, Member.php, Payment.php, Category.php, Delivery.php

その他Entity

  • AuthorityRole.php, BaseInfo.php, Block.php, Calendar.php, ClassCategory.php, ClassName.php, Csv.php, CustomerAddress.php, CustomerFavoriteProduct.php, DeliveryTime.php, Layout.php, LoginHistory.php, MailHistory.php, MailTemplate.php, News.php, OrderPdf.php, Page.php, Plugin.php, ProductImage.php, ProductStock.php, ProductTag.php, Tag.php, TaxRule.php, Template.php

目的

  • Symfony 7/Doctrine ORM 3.x 互換性の向上
  • Symfony Form の PRE_SET_DATA イベント中の初期化エラー回避
  • Enterprise版との型宣言パターン統一

修正パターン

DateTime型

// Before
/**
 * @var \DateTime
 */
private $create_date;

// After
private ?\DateTime $create_date = null;

Collection型

// Before
/**
 * @var Collection<int, OrderItem>
 */
private $OrderItems;

// After
/**
 * @var Collection<int, OrderItem>
 */
private Collection $OrderItems;

テスト計画

  • PHPStan静的解析でエラーなし(確認済み)
  • php-cs-fixerでスタイル違反なし(確認済み)
  • 既存のPHPUnitテストが全てパス

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • 多数のエンティティで、日時系フィールドを null 許容の型付きプロパティ(初期値は null)へ統一し、型安全性を向上しました。
    • 関連するコレクションプロパティも Collection 型として明示化し、公開アクセサの型宣言の整合性を図りました。

- 全ての日付プロパティに nullable DateTime 型宣言 (?\DateTime $property = null) を追加
- Collection 型宣言を追加(PHPDoc のジェネリクス情報は型推論のため維持)
- DateTime プロパティの冗長な PHPDoc @var アノテーションを削除
- Symfony 7/Doctrine ORM 3.x 互換性の向上
- Symfony Form の PRE_SET_DATA 初期化要件に対応

34個の Entity ファイルに一貫した型宣言パターンを適用。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dotani1111 dotani1111 added this to the 4.4.0 milestone Jan 14, 2026
@dotani1111 dotani1111 added the refactor リファクタリング label Jan 14, 2026
@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

多数のDoctrineエンティティで未型付プロパティをPHPの型付きプロパティへ変更します。日時フィールドをnullableなDateTime型、関連コレクションをCollection型として宣言し、ORMマッピングを維持します。OrderPdfの日時setter引数もDateTime型へ変更します。

Changes

エンティティプロパティ型宣言

Layer / File(s) Summary
日時プロパティの型付け
src/Eccube/Entity/*.php
日時関連プロパティを?\DateTime型へ変更し、必要なフィールドをnullで初期化します。既存のORM列マッピングは維持されます。
コレクションプロパティの型付け
src/Eccube/Entity/{Block,Category,ClassName,Customer,Delivery,Layout,Order,Page,Payment,Product,Shipping,Tag,Cart}.php
関連コレクションをCollection型へ変更し、既存の関連マッピングと初期化を維持します。
OrderPdfアクセサ型の更新
src/Eccube/Entity/OrderPdf.php
setCreateDatesetUpdateDateの引数を\DateTime型へ変更し、issue_dateの`\DateTime

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: dotani1111, ttokoro20240902

Poem

🐰 型をまとって跳ねる日々、
DateTimeはnullの野原へ、
Collectionは輪になって、
ORMの道をそのまま進み、
コードは軽やか春うらら。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed DateTime と Collection プロパティへのネイティブ型宣言追加という、変更内容の主眼を簡潔に表しています。
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.
✨ 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.

@nanasess
nanasess enabled auto-merge May 14, 2026 06:04

@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: 2

🤖 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 `@src/Eccube/Entity/Member.php`:
- Around line 104-108: Member entity declares create_date and update_date as
nullable properties but Doctrine mapping requires NOT NULL and there are no
lifecycle callbacks found; add lifecycle callback methods to Member (or its
parent) using #[ORM\PrePersist] to set create_date and update_date when first
persisted and #[ORM\PreUpdate] (or also in PrePersist) to update update_date on
changes, ensure the class retains #[ORM\HasLifecycleCallbacks], and/or update
setPropertiesFromArray/form handling to always initialize these fields before
persist so DB NOT NULL constraints are satisfied (reference symbols:
create_date, update_date, #[ORM\HasLifecycleCallbacks], #[ORM\PrePersist],
#[ORM\PreUpdate], setPropertiesFromArray, Member.php, AbstractEntity.php).

In `@src/Eccube/Entity/OrderPdf.php`:
- Around line 61-64: The setters setCreateDate and setUpdateDate accept
\DateTime|string while the properties $create_date and $update_date are typed
?\DateTime, which can cause a TypeError when a string is assigned; change the
method signatures to accept ?\DateTime (e.g. setCreateDate(?\DateTime
$create_date): static and setUpdateDate(?\DateTime $update_date): static) and
assign directly to the typed properties, or if you need to keep string
compatibility normalize/parse strings to \DateTime inside the setters before
assigning to $create_date/$update_date.
🪄 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: 472995f3-0586-4720-bd71-a359bb0818f2

📥 Commits

Reviewing files that changed from the base of the PR and between 27a19d8 and 4feaa20.

📒 Files selected for processing (34)
  • src/Eccube/Entity/AuthorityRole.php
  • src/Eccube/Entity/BaseInfo.php
  • src/Eccube/Entity/Block.php
  • src/Eccube/Entity/Calendar.php
  • src/Eccube/Entity/Cart.php
  • src/Eccube/Entity/Category.php
  • src/Eccube/Entity/ClassCategory.php
  • src/Eccube/Entity/ClassName.php
  • src/Eccube/Entity/Csv.php
  • src/Eccube/Entity/Customer.php
  • src/Eccube/Entity/CustomerAddress.php
  • src/Eccube/Entity/CustomerFavoriteProduct.php
  • src/Eccube/Entity/Delivery.php
  • src/Eccube/Entity/DeliveryTime.php
  • src/Eccube/Entity/Layout.php
  • src/Eccube/Entity/LoginHistory.php
  • src/Eccube/Entity/MailHistory.php
  • src/Eccube/Entity/MailTemplate.php
  • src/Eccube/Entity/Member.php
  • src/Eccube/Entity/News.php
  • src/Eccube/Entity/Order.php
  • src/Eccube/Entity/OrderPdf.php
  • src/Eccube/Entity/Page.php
  • src/Eccube/Entity/Payment.php
  • src/Eccube/Entity/Plugin.php
  • src/Eccube/Entity/Product.php
  • src/Eccube/Entity/ProductClass.php
  • src/Eccube/Entity/ProductImage.php
  • src/Eccube/Entity/ProductStock.php
  • src/Eccube/Entity/ProductTag.php
  • src/Eccube/Entity/Shipping.php
  • src/Eccube/Entity/Tag.php
  • src/Eccube/Entity/TaxRule.php
  • src/Eccube/Entity/Template.php

Comment thread src/Eccube/Entity/Member.php Outdated
Comment thread src/Eccube/Entity/OrderPdf.php Outdated
@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.21%. Comparing base (1cfea14) to head (2ca2314).

Additional details and impacted files
@@            Coverage Diff             @@
##              4.4    #6569      +/-   ##
==========================================
+ Coverage   77.11%   77.21%   +0.10%     
==========================================
  Files         547      547              
  Lines       27163    27163              
==========================================
+ Hits        20946    20975      +29     
+ Misses       6217     6188      -29     
Flag Coverage Δ
Unit 77.21% <ø> (+0.10%) ⬆️

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.

nanasess and others added 5 commits May 27, 2026 14:09
setCreateDate / setUpdateDate のパラメータ型を \DateTime|string から \DateTime に
変更し、本 PR で厳格化した ?\DateTime プロパティとの整合性を取る。
コードベース上、両 setter への呼び出しはすべて \DateTime オブジェクト渡しで
あり、文字列リテラル渡しの実例はないため後方互換に影響なし。

なお $issue_date プロパティは PDF 出力時にフォーマット済み文字列を受け取る
ケースがあるため、意図的に \DateTime|string のユニオン型を維持する旨を
コメントで明記した。

Co-Authored-By: Claude <noreply@anthropic.com>
@nanasess nanasess self-assigned this Jul 24, 2026
nanasess and others added 3 commits July 24, 2026 10:47
…-declarations

# Conflicts:
#	src/Eccube/Entity/AuthorityRole.php
#	src/Eccube/Entity/BaseInfo.php
#	src/Eccube/Entity/Block.php
#	src/Eccube/Entity/Calendar.php
#	src/Eccube/Entity/Cart.php
#	src/Eccube/Entity/Category.php
#	src/Eccube/Entity/ClassCategory.php
#	src/Eccube/Entity/ClassName.php
#	src/Eccube/Entity/Csv.php
#	src/Eccube/Entity/Customer.php
#	src/Eccube/Entity/CustomerAddress.php
#	src/Eccube/Entity/CustomerFavoriteProduct.php
#	src/Eccube/Entity/Delivery.php
#	src/Eccube/Entity/DeliveryTime.php
#	src/Eccube/Entity/Layout.php
#	src/Eccube/Entity/LoginHistory.php
#	src/Eccube/Entity/MailHistory.php
#	src/Eccube/Entity/MailTemplate.php
#	src/Eccube/Entity/Member.php
#	src/Eccube/Entity/News.php
#	src/Eccube/Entity/Order.php
#	src/Eccube/Entity/OrderPdf.php
#	src/Eccube/Entity/Page.php
#	src/Eccube/Entity/Payment.php
#	src/Eccube/Entity/Plugin.php
#	src/Eccube/Entity/Product.php
#	src/Eccube/Entity/ProductClass.php
#	src/Eccube/Entity/ProductImage.php
#	src/Eccube/Entity/ProductStock.php
#	src/Eccube/Entity/ProductTag.php
#	src/Eccube/Entity/Shipping.php
#	src/Eccube/Entity/Tag.php
#	src/Eccube/Entity/TaxRule.php
#	src/Eccube/Entity/Template.php
…-declarations

# Conflicts:
#	src/Eccube/Entity/Product.php

@dotani1111 dotani1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@nanasess
nanasess merged commit 89dec55 into EC-CUBE:4.4 Jul 27, 2026
115 checks passed
@nanasess
nanasess deleted the refactor/entity-type-declarations branch July 27, 2026 05:32
ttokoro20240902 added a commit that referenced this pull request Jul 28, 2026
- create_date / update_date を `@var` docblock から native 型宣言
  (`?\DateTime ... = null`) へ変更。#6569 で全 Entity が統一済みで、
  旧スタイルが残るのは Faq のみだった(PHPStan level6 は docblock でも
  通るため CI では検出されない)
- setProduct / setCategory の「もう一方を黙って null にする」副作用を撤去し、
  コアの他 Entity と同じ素の代入に戻す。区分の導出は getFaqType() に集約
  されており、管理画面に両方を設定する経路は無い旨を PHPDoc に明記
- FaqTest を排他検証から getFaqType() の3区分導出検証へ置き換え

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor リファクタリング

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants