Skip to content

Bug: UserEntityFactory/SubscriptionFactory throw when subscription_tier is omitted / UserEntityFactory・SubscriptionFactoryでsubscription_tier省略時に例外が発生する #559

Description

@zigzagdev

Motivation / 目的

subscription_tier was already made optional at the CreateUserCommand/CreateUserUseCase level (see the recent optional-subscription_tier fixes), but the Domain-layer factories still assumed the key was always present and non-null:

  • UserEntityFactory::build() accessed $data['subscription_tier'] directly (no fallback)
  • SubscriptionFactory::build() called SubscriptionTier::from($data['tier']) directly

Any caller that omitted subscription_tier (or passed null) would hit a TypeError from SubscriptionTier::from(null) instead of getting the intended free default. Existing call sites happened to avoid this only because they resolved a default before calling into the factories — the Domain layer itself had no defense.

subscription_tierCreateUserCommand/CreateUserUseCase側では既に任意項目化されていましたが、Domain層のファクトリ(UserEntityFactory, SubscriptionFactory)は値が必ず存在する前提のままで、省略時のフォールバックがありませんでした。

What to do / 実施内容

  • SubscriptionFactory::build(): default the tier to SubscriptionTier::Free->value when $data['tier'] is null
  • UserEntityFactory::build(): pass $data['subscription_tier'] ?? null instead of a direct array access

Tests / テスト

  • test_build_defaults_subscription_tier_to_free_when_omitted

Status

Fixed in #558.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions