php-service-bus / service-bus

PHP Service Bus (publish-subscribe pattern) implementation
MIT License
349 stars 18 forks source link

AggregateId is not marked as immutable #147

Closed andrew-demb closed 3 years ago

andrew-demb commented 4 years ago

Is it intended - allow to add side effects/mutations in descendants?

https://github.com/php-service-bus/event-sourcing/blob/v4.2.0/src/AggregateId.php

mmasiukevich commented 4 years ago

An abstract class, by definition, cannot be immutable. You can expand it as you need while maintaining the base contract.

andrew-demb commented 4 years ago

You can force by contract on abstract class info about immutability. All descendants will be required to be immutable also, if they not - they will violate LSP.

https://psalm.dev/r/4c56e36782 (extends without immutable annotation)

Psalm output (using commit 19f88a2): 

ERROR: MissingImmutableAnnotation - 24:25 - AggregateId is marked immutable, but BicycleId is not marked immutable

https://psalm.dev/r/0cd6a289ad (extends and provide side effect)

mmasiukevich commented 4 years ago

Well, maybe that makes sense.