jorge07 / symfony-6-es-cqrs-boilerplate

Symfony 6 DDD ES CQRS backend boilerplate.
MIT License
1.07k stars 187 forks source link

DBAL types for value object #78

Closed alekseytupichenkov closed 4 years ago

alekseytupichenkov commented 6 years ago

I'm not sure, but, what do you think about using DBAL types for value objects? In case of using DBAL types, we can guarantee that all entities have or VO or null

PS: It's just proposal, so code can have code-style or other problems :)

coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 270


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Infrastructure/User/Auth/Auth.php 2 3 66.67%
src/Infrastructure/User/ORM/Type/HashedPasswordType.php 6 7 85.71%
src/Domain/Shared/ValueObject/AbstractUuid.php 16 18 88.89%
src/Infrastructure/Share/ORM/Type/AbstractStringType.php 6 8 75.0%
src/Infrastructure/Share/ORM/Type/AbstractUuidType.php 7 12 58.33%
<!-- Total: 52 63 82.54% -->
Totals Coverage Status
Change from base Build 263: -1.4%
Covered Lines: 541
Relevant Lines: 574

💛 - Coveralls
jorge07 commented 6 years ago

I think this make sense when we've complex VO, but having it for all the VO is a extra work that can easily incur in overengineering. I have to think on it more but I'm quite open.

alekseytupichenkov commented 6 years ago

Yeah, I understand, but it's really strange when I expect some VO in read model but got scalar value

jorge07 commented 6 years ago

I really avoid hydration in read model as much as possible, mostly for performance reasons

alekseytupichenkov commented 6 years ago

Hm... I see, I think it's depends on task.

So, in case of create read model without hydration, maybe better way to save scalar value every time? I'm about \App\Infrastructure\User\Query\Projections\UserView::deserialize and \App\Infrastructure\User\Query\Projections\UserView::changeEmail Something like this

class UserView implements UserViewInterface
{
    public static function fromSerializable(Serializable $event): self
    {
        return self::deserialize($event->serialize());
    }

    /**
     * @throws \Assert\AssertionFailedException
     */
    public static function deserialize(array $data): self
    {
        $instance = new self();

        $instance->uuid = $data['uuid'];
        $instance->email = $data['email'];
        $instance->password = $data['password'];

        return $instance;
    }

    public function serialize(): array
    {
        return [
            'uuid'  => $this->getId(),
            'email' => $this->email,
        ];
    }

    public function uuid(): string
    {
        return $this->uuid;
    }

    public function email(): string
    {
        return $this->email;
    }

    public function changeEmail(Email $email): void
    {
        $this->email = $email->toString();
    }

    public function hashedPassword(): string
    {
        return $this->password;
    }

    public function getId(): string
    {
        return $this->uuid;
    }

    /** @var string */
    private $uuid;

    /** @var string */
    private $email;

    /** @var string */
    private $password;
}
alekseytupichenkov commented 5 years ago

@jorge07 Done, also added more tests

jorge07 commented 5 years ago

Missing test for nullable values in ORM types.

jorge07 commented 4 years ago

/stale