Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
18 / 18
Item
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
7 / 7
8
100.00% covered (success)
100.00%
18 / 18
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 uuid
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 type
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 quantity
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 fromArray
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 toArray
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 equals
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
<?php
declare(strict_types=1);
namespace App\Order\Domain\ValueObject;
use App\Shared\ValueObjectInterface;
use Assert\Assertion;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
final class Item implements ValueObjectInterface
{
    private UuidInterface $uuid;
    private ProductType $type;
    private int $quantity;
    private function __construct(
        UuidInterface $uuid,
        ProductType $type,
        int $quantity
    ) {
        $this->uuid = $uuid;
        $this->type = $type;
        $this->quantity = $quantity;
    }
    public function uuid(): UuidInterface
    {
        return $this->uuid;
    }
    public function type(): ProductType
    {
        return $this->type;
    }
    public function quantity(): int
    {
        return $this->quantity;
    }
    public static function fromArray(array $data): self
    {
        Assertion::uuid($data['uuid']);
        return new self(
            Uuid::fromString($data['uuid']),
            ProductType::fromString($data['type']),
            (int) $data['quantity']
        );
    }
    public function toArray(): array
    {
        return [
            'uuid' => $this->uuid->toString(),
            'type' => $this->type->toString(),
            'quantity' => $this->quantity,
        ];
    }
    public function equals(ValueObjectInterface $valueObject): bool
    {
        if (!$valueObject instanceof self) {
            return false;
        }
        return $valueObject->toArray() === $valueObject->toArray();
    }
}