-
Notifications
You must be signed in to change notification settings - Fork 693
型宣言の適用とPHPStan Level 6対応 #6474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nanasess
wants to merge
10
commits into
EC-CUBE:4.3-symfony7
Choose a base branch
from
nanasess:apply-type-declarations
base: 4.3-symfony7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
型宣言の適用とPHPStan Level 6対応 #6474
+2,970
−2,955
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./vendor/bin/patch-type-declarations 実行後に発生した致命的エラーを修正: - void 型関数が値を返すエラーを修正 - Controller の moveSortNo() メソッド: void → Response に変更し、トークン無効時の例外処理を追加 - CartService::getUser(): void → ?UserInterface に変更 - CacheUtil::forceClearCache(): void → string に変更 - PointProcessor::addDiscountItem(): void → ?ProcessResult に変更(インターフェースも修正) - 戻り値型の不整合を修正 - OrderPdfRepository::save(): bool → void に変更(AbstractRepository と互換性を確保) - ComposerServiceFactory::createService(): 冗長な object 型を削除 - マジックメソッドの型修正 - AbstractMasterEntity::__set(): mixed → void に変更(PHP 仕様に準拠) - インターフェースの型定義を改善 - ItemHolderInterface のセッターメソッド: ItemHolderInterface → self に変更(型安全性向上) - ItemHolderInterface::getShippings(): ArrayCollection → Collection に変更 これにより bin/console コマンドが正常に動作するようになりました。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
patch-type-declarations 実行後に mixed になった返り値の型を、 実際の戻り値に基づいてより具体的な型に修正: - データベース関連: false|string, string - 管理画面統計: array, int|string|null - Doctrine型変換: ?string, ?\DateTimeInterface - エンティティ: ?Master\OrderStatus - コレクション: string - 設定管理: ?array, ?string - PDF出力: string - 状態遷移: ?\Symfony\Component\Workflow\Transition 修正完了: 19件 仕様上mixed保持: 14件(DIコンテナ、マジックメソッド等) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
PHPStan 静的解析で検出されたエラーを修正: - AbstractEntity::offsetGet(): 戻り値が欠落していた問題を修正 - メソッドが見つからない場合に null を返すように修正 - EntityToIdTransformer::reverseTransform(): ジェネリック型 T を使用した型宣言エラーを修正 - ネイティブ型宣言を ?T から ?object に変更(PHPDoc で @return T|null を維持) - PHPDoc の @return 型アノテーションを修正 - AdminController: array → array<string, int> - InstallController::getSessionData(): array → mixed - Controller の moveSortNo(): Response|void → Response - ItemHolderInterface 実装クラスの戻り値型を統一 - Cart/Order/CartItem/OrderItem の setter メソッド: void → static に変更 - setDiscount/setCharge/setTax: メソッドチェーン対応のため static を返すように修正 - Composer サービスの @return mixed アノテーションを追加 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit removes redundant `(string)` type casting from multiple methods across the codebase. The changes improve code readability and maintainability without altering functionality.
c2b28ee to
1c040e5
Compare
Updated return types in `Cart` and `Member` entities to improve type safety and align with modern PHP standards. - Changed `setTotalPrice` and `setTotal` methods in `Cart` to return `static` instead of `Cart`. - Updated `getSalt` method in `Member` to return `?string` instead of `string`.
|
うちの会社でもPHPStan使ってて、この方宣言がないとめっちゃ怒られます。 |
Updated return types in various entity and service methods to reflect nullable values. This improves type safety and aligns with modern PHP practices.
Updated test cases to use string type for numeric values in assertions to ensure consistency and prevent type-related issues.
4933177 to
2425a88
Compare
型定義付与ツール適用後のPHPUnitエラー(約30件)を修正。 ## 修正内容 ### 主な修正 - Shipping::getMailSendDate(): \DateTime → ?\DateTime - ClassName::getBackendName(): string → ?string ### 全エンティティ(32ファイル) getCreateDate()とgetUpdateDate()の戻り値型を修正: - public function getCreateDate(): \DateTime → ?\DateTime - public function getUpdateDate(): \DateTime → ?\DateTime ## 根本原因 1. 型定義付与ツールがnullable=trueのカラムに対して非nullable型を設定 2. 新規エンティティ作成時(未保存状態)にcreate_date/update_dateがnull 3. Twigテンプレート描画時にTypeErrorが発生し500エラー ## 解決したエラー - OrderControllerTest: 8件 - ClassCategoryControllerTest: 3件 - ProductControllerTest: 1件 - その他管理画面テスト: 約18件 合計: 約30件のエラーを解決 ## 対象エンティティ AuthorityRole, BaseInfo, Block, Calendar, Cart, Category, ClassCategory, ClassName, Csv, Customer, CustomerAddress, CustomerFavoriteProduct, Delivery, DeliveryTime, Layout, LoginHistory, MailTemplate, Member, News, Order, OrderPdf, Page, Payment, Plugin, Product, ProductClass, ProductImage, ProductStock, ProductTag, Shipping, TaxRule, Template 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
PHPUnitテストで発生していた型エラーを修正: - PaymentResult::getResponse(): Response|null に変更し、nullチェックを追加 - Tag::getName(): string|null に変更し、__toString()でnull対応 - Order::getUsePoint(): string|null に変更(PointTrait/ItemHolderInterface) - HelpControllerTest: デバッグ用のエラーメッセージを追加 これにより以下のテストエラーが解消: - ShoppingControllerTest::testCompleteWithLogin 他7件(PaymentResult) - TagControllerTest::testEditInvalid(Tag::getName) - ShoppingControllerTest::testPaymentWithError(Order::getUsePoint) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
2425a88 to
0aa0d94
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概要(Overview・Refs Issue)
PHPの型宣言を適用し、PHPStan Level 6の静的解析に対応するための変更です。
主な変更内容:
./vendor/bin/patch-type-declarationsによる型宣言の自動適用方針(Policy)
実装に関する補足(Appendix)
型宣言エラーの修正
moveSortNo(): void → Response + トークン無効時の例外処理追加CartService::getUser(): void → ?UserInterfaceCacheUtil::forceClearCache(): void → string__set(): mixed → void(PHP仕様に準拠)ItemHolderInterfaceのセッターメソッド: ItemHolderInterface → self(メソッドチェーン対応)影響範囲
テスト(Test)
相談(Discussion)
特になし
マイナーバージョン互換性保持のための制限事項チェックリスト
レビュワー確認項目
🤖 Generated with Claude Code