$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 PreconditionsException('value must be positive number:' . $value); } $this->value = $value; } //(snip) *UFN1SJDF Ձ֨Ҏ্ͷ
$elements; public function addItem(Item $item, ItemCount $count) { if ($item->stock()->isInsufficient($count)) { throw new PreconditionsException('stock is insufficient'); } $this->elements->push(new CartElement($item, $count)); } $BSUΧʔτʹΛೖΕΔ ࡏݿ͕ෆ͍ͯ͠Δ͔ʁ
$elements; public function addItem(Item $item, ItemCount $count) { if ($item->stock()->isInsufficient($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
$date; public function __construct(Carbon $date) { $this->date = $date; } public function age(): int { return $this->date->age; } } ੜ݄Λ7BMVF0CKFDUԽ $BSCPOΛϥοϓ ඞཁͳૢ࡞ͷΈ࣮