refactor(entity): DateTime および Collection プロパティにネイティブ型宣言を追加 - #6569
Conversation
- 全ての日付プロパティに 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>
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthrough多数のDoctrineエンティティで未型付プロパティをPHPの型付きプロパティへ変更します。日時フィールドをnullableな Changesエンティティプロパティ型宣言
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 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
📒 Files selected for processing (34)
src/Eccube/Entity/AuthorityRole.phpsrc/Eccube/Entity/BaseInfo.phpsrc/Eccube/Entity/Block.phpsrc/Eccube/Entity/Calendar.phpsrc/Eccube/Entity/Cart.phpsrc/Eccube/Entity/Category.phpsrc/Eccube/Entity/ClassCategory.phpsrc/Eccube/Entity/ClassName.phpsrc/Eccube/Entity/Csv.phpsrc/Eccube/Entity/Customer.phpsrc/Eccube/Entity/CustomerAddress.phpsrc/Eccube/Entity/CustomerFavoriteProduct.phpsrc/Eccube/Entity/Delivery.phpsrc/Eccube/Entity/DeliveryTime.phpsrc/Eccube/Entity/Layout.phpsrc/Eccube/Entity/LoginHistory.phpsrc/Eccube/Entity/MailHistory.phpsrc/Eccube/Entity/MailTemplate.phpsrc/Eccube/Entity/Member.phpsrc/Eccube/Entity/News.phpsrc/Eccube/Entity/Order.phpsrc/Eccube/Entity/OrderPdf.phpsrc/Eccube/Entity/Page.phpsrc/Eccube/Entity/Payment.phpsrc/Eccube/Entity/Plugin.phpsrc/Eccube/Entity/Product.phpsrc/Eccube/Entity/ProductClass.phpsrc/Eccube/Entity/ProductImage.phpsrc/Eccube/Entity/ProductStock.phpsrc/Eccube/Entity/ProductTag.phpsrc/Eccube/Entity/Shipping.phpsrc/Eccube/Entity/Tag.phpsrc/Eccube/Entity/TaxRule.phpsrc/Eccube/Entity/Template.php
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
setCreateDate / setUpdateDate のパラメータ型を \DateTime|string から \DateTime に 変更し、本 PR で厳格化した ?\DateTime プロパティとの整合性を取る。 コードベース上、両 setter への呼び出しはすべて \DateTime オブジェクト渡しで あり、文字列リテラル渡しの実例はないため後方互換に影響なし。 なお $issue_date プロパティは PDF 出力時にフォーマット済み文字列を受け取る ケースがあるため、意図的に \DateTime|string のユニオン型を維持する旨を コメントで明記した。 Co-Authored-By: Claude <noreply@anthropic.com>
…-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
- 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>
概要
Entityファイルの DateTime および Collection プロパティにPHP 8のネイティブ型宣言を追加しました。
変更内容
?\DateTime $property = null) を追加@varアノテーションを削除対象ファイル(34ファイル)
主要Entity
関連Entity
その他Entity
目的
修正パターン
DateTime型
Collection型
テスト計画
🤖 Generated with Claude Code
Summary by CodeRabbit
null)へ統一し、型安全性を向上しました。Collection型として明示化し、公開アクセサの型宣言の整合性を図りました。