for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Simara\Cart\Domain\Cart;
use Simara\Cart\Domain\Price;
use Simara\Cart\Domain\Prices\Prices;
final class Item
{
private int $generatedId;
$generatedId
/**
* @throws AmountMustBePositiveException
*/
public function __construct(
private string $productId,
private int $amount
) {
$this->checkAmount($amount);
}
public function toDetail(Prices $prices): ItemDetail
return new ItemDetail($this->productId, $prices->unitPrice($this->productId), $this->amount);
public function getProductId(): string
return $this->productId;
public function add(int $amount): void
$this->amount = $this->amount + $amount;
private function checkAmount(int $amount): void
if ($amount <= 0) {
throw new AmountMustBePositiveException();
public function changeAmount(int $amount): void
$this->amount = $amount;
public function calculatePrice(Prices $prices): Price
return $prices->unitPrice($this->productId)->multiply($this->amount);