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\Cart\ItemDetail;
use Simara\Cart\Domain\Price;
use Simara\Cart\Domain\Prices\Prices;
class Item
{
private $generatedId;
$generatedId
private string $productId;
private int $amount;
/**
* @throws AmountMustBePositiveException
*/
public function __construct(string $productId, int $amount)
$this->checkAmount($amount);
$this->productId = $productId;
$this->amount = $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
public function calculatePrice(Prices $prices): Price
return $prices->unitPrice($this->productId)->multiply($this->amount);