Skip to content

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

Open
nanasess wants to merge 8 commits into
EC-CUBE:4.4from
nanasess:refactor/entity-type-declarations
Open

refactor(entity): DateTime および Collection プロパティにネイティブ型宣言を追加#6569
nanasess wants to merge 8 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
    • 多数のエンティティで日時系フィールドを明示的なnullable型(?\DateTime)へ移行し、コレクション関連プロパティを明確なコレクション型へ変更しました。
    • 公開APIや挙動は維持しつつ、型安全性と保守性を向上させる内部表現の近代化を実施しました。

- 全ての日付プロパティに 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

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: d18a0180-7dea-4e29-bdff-c926bf311a4d

📥 Commits

Reviewing files that changed from the base of the PR and between e13d49e and f958703.

📒 Files selected for processing (1)
  • src/Eccube/Entity/Shipping.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Eccube/Entity/Shipping.php

📝 Walkthrough

Walkthrough

このPRは多数のDoctrineエンティティで未型付プロパティをPHPの型付きプロパティへ置き換えます。日時フィールドを ?\DateTime(必要に応じて = null)へ、コレクションを Collection 型へ明示化し、ORMマッピングと既存のメソッド署名は維持します。

Changes

Entity Property Type Declarations

Layer / File(s) Summary
All entity property typing updates
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
多数のエンティティで日時フィールドを ?\DateTime(nullable)へ、OneToMany等のコレクションを Collection へ明示的に型付け。ORM属性/列定義と既存のアクセサ/ミューテータ署名は維持。OrderPdf は一部メソッド引数の型を \DateTime に絞り込んでいる。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 型をまとい跳ねる日々、
プロパティはやさしく整列し、
DateTime は nullable の春を待ち、
Collection はみんなで手をつなぎ、
小さな変更でコードは軽やかに。

🚥 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 プロパティへのネイティブ型宣言の追加というリファクタリングの中心的な変更を明確に示しており、34ファイルにわたる一貫した変更を簡潔に表現しています。
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@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
Comment thread src/Eccube/Entity/OrderPdf.php
@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 74.88%. Comparing base (ae3c3ee) to head (3abbb58).

Additional details and impacted files
@@            Coverage Diff             @@
##              4.4    #6569      +/-   ##
==========================================
- Coverage   74.91%   74.88%   -0.03%     
==========================================
  Files         463      463              
  Lines       24029    24029              
==========================================
- Hits        18001    17995       -6     
- Misses       6028     6034       +6     
Flag Coverage Δ
Unit 74.88% <ø> (-0.03%) ⬇️

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

2 participants