$value; /** * @param int $value */ public function __construct(int $value) { $this->value = $value; } public function value(): int { return $this->value; } } *UFN*E ৼΔ͍ʢԋࢉʣ͕ແ͍
$value; public function __construct(int $value = 0) { if ($value < 0) { throw new InvariantException('value must be positive number:' . $value); } $this->value = $value; } //(snip) *UFN1SJDF Ձ֨Ҏ্ͷ
$elements; public function addItem(Item $item, ItemCount $count) { if (!$item->isSufficient($count)) { throw new InvariantException('stock is insufficient'); } $this->elements->push(new CartElement($item, $count)); } $BSU ࡏݿ͕Γͳ͚Εྫ֎
$elements; public function addItem(Item $item, ItemCount $count) { if (!$item->isSufficient($count)) { throw new PreconditionsException('stock is insufficient'); } $this->elements->push(new CartElement($item, $count)); } $BSU ΧʔτཁૉΛՃ
public function __construct(EloquentItem $eloquent) { $this->eloquent = $eloquent; } public function findById(ItemId $id): Item { $item = $this->eloquent->find($id->value()); if (empty($item)) { throw new NotFoundException('item not found'); } return $item->toDomain(); } } &MPRVFOU*UFN3FQPTJUPSZ
public function __construct(EloquentItem $eloquent) { $this->eloquent = $eloquent; } public function findById(ItemId $id): Item { $item = $this->eloquent->find($id->value()); if (empty($item)) { throw new NotFoundException('item not found'); } return $item->toDomain(); } } &MPRVFOU*UFN3FQPTJUPSZ
$table = 'items'; public function toDomain(): Item { return new Item( new ItemId($this->id), $this->name, new ItemPrice($this->price), new Stock($this->stock) ); } } &MPRVFOU*UFN
if (empty($cart)) { throw new NotFoundException('cart not found'); } return $cart; } public function store(Cart $cart) { $this->session->put(static::SESSION_KEY, $cart); } )UUQ4FTTJPO$BSU3FQPTJUPSZ ηογϣϯ͔Βͷೖग़ྗ