From 88abd2e16889d0e0a4f7fd773ead401624f92fc6 Mon Sep 17 00:00:00 2001 From: bwaidelich Date: Thu, 3 Aug 2023 10:39:31 +0200 Subject: [PATCH] FEATURE: PHP 8.1 compatibility --- .github/workflows/php.yml | 8 ++++++-- composer.json | 2 +- src/Helpers/InMemoryEventStream.php | 4 ++-- src/Types/AppendCondition.php | 6 +++--- src/Types/Event.php | 10 +++++----- src/Types/EventData.php | 2 +- src/Types/EventEnvelope.php | 6 +++--- src/Types/EventId.php | 4 ++-- src/Types/EventType.php | 4 ++-- src/Types/Events.php | 4 ++-- src/Types/ExpectedHighestSequenceNumber.php | 4 ++-- src/Types/SequenceNumber.php | 7 +++---- src/Types/StreamQuery/Criteria.php | 4 ++-- .../Criteria/EventTypesAndTagsCriterion.php | 6 +++--- src/Types/StreamQuery/Criteria/EventTypesCriterion.php | 4 ++-- src/Types/StreamQuery/Criteria/TagsCriterion.php | 4 ++-- src/Types/StreamQuery/StreamQuery.php | 4 ++-- src/Types/StreamQuery/StreamQuerySerializer.php | 6 +++++- src/Types/Tag.php | 6 +++--- src/Types/Tags.php | 4 ++-- 20 files changed, 53 insertions(+), 46 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 75406a4..d93af02 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,14 +12,18 @@ permissions: jobs: build: + strategy: + matrix: + php-versions: [ '8.1', '8.2', '8.3' ] + runs-on: ubuntu-latest steps: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' - + php-version: ${{ matrix.php-versions }} + - name: Checkout code uses: actions/checkout@v3 diff --git a/composer.json b/composer.json index dadb26a..dd7a49d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">=8.2", + "php": ">=8.1", "ramsey/uuid": "^4.7", "psr/clock": "^1", "webmozart/assert": "^1.11" diff --git a/src/Helpers/InMemoryEventStream.php b/src/Helpers/InMemoryEventStream.php index 7517068..fa5f5fd 100644 --- a/src/Helpers/InMemoryEventStream.php +++ b/src/Helpers/InMemoryEventStream.php @@ -14,13 +14,13 @@ * Usage: * $eventStream = InMemoryEventStream::create($event1 ,$event2); */ -final readonly class InMemoryEventStream implements EventStream +final class InMemoryEventStream implements EventStream { /** * @param EventEnvelope[] $eventEnvelopes */ private function __construct( - private array $eventEnvelopes, + private readonly array $eventEnvelopes, ) { } diff --git a/src/Types/AppendCondition.php b/src/Types/AppendCondition.php index d95ab66..0e15ac9 100644 --- a/src/Types/AppendCondition.php +++ b/src/Types/AppendCondition.php @@ -10,11 +10,11 @@ /** * Condition for {@see EventStore::append()} */ -final readonly class AppendCondition +final class AppendCondition { public function __construct( - public StreamQuery $query, - public ExpectedHighestSequenceNumber $expectedHighestSequenceNumber, + public readonly StreamQuery $query, + public readonly ExpectedHighestSequenceNumber $expectedHighestSequenceNumber, ) { } diff --git a/src/Types/Event.php b/src/Types/Event.php index 9a4ecfa..a35c45f 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -7,13 +7,13 @@ /** * The raw low-level event that is stored in the Events Store */ -final readonly class Event +final class Event { public function __construct( - public EventId $id, // required for deduplication - public EventType $type, - public EventData $data, // opaque, no size limit? - public Tags $tags, + public readonly EventId $id, // required for deduplication + public readonly EventType $type, + public readonly EventData $data, // opaque, no size limit? + public readonly Tags $tags, // add metadata ? ) { } diff --git a/src/Types/EventData.php b/src/Types/EventData.php index a07c5af..9c6095b 100644 --- a/src/Types/EventData.php +++ b/src/Types/EventData.php @@ -9,7 +9,7 @@ /** * String-based data of an event (usually the JSON-encoded payload of a domain event */ -final readonly class EventData implements JsonSerializable +final class EventData implements JsonSerializable { private function __construct( public readonly string $value, diff --git a/src/Types/EventEnvelope.php b/src/Types/EventEnvelope.php index 82d4260..685de06 100644 --- a/src/Types/EventEnvelope.php +++ b/src/Types/EventEnvelope.php @@ -11,12 +11,12 @@ * * */ -final readonly class EventEnvelope +final class EventEnvelope { public function __construct( - public SequenceNumber $sequenceNumber, + public readonly SequenceNumber $sequenceNumber, //public DateTimeImmutable $recordedAt, // do we need it - public Event $event, + public readonly Event $event, ) { } } diff --git a/src/Types/EventId.php b/src/Types/EventId.php index 7c59367..6f3a39f 100644 --- a/src/Types/EventId.php +++ b/src/Types/EventId.php @@ -11,9 +11,9 @@ /** * Globally unique identifier of an event (usually formatted as UUID v4) */ -final readonly class EventId implements JsonSerializable +final class EventId implements JsonSerializable { - private function __construct(public string $value) + private function __construct(public readonly string $value) { Assert::notEmpty($this->value); } diff --git a/src/Types/EventType.php b/src/Types/EventType.php index 5bf0e14..e4f6178 100644 --- a/src/Types/EventType.php +++ b/src/Types/EventType.php @@ -10,9 +10,9 @@ /** * The type of an event, e.g. "CustomerRenamed" */ -final readonly class EventType implements JsonSerializable +final class EventType implements JsonSerializable { - private function __construct(public string $value) + private function __construct(public readonly string $value) { Assert::notEmpty($this->value); } diff --git a/src/Types/Events.php b/src/Types/Events.php index 2ef6c5c..4ec0017 100644 --- a/src/Types/Events.php +++ b/src/Types/Events.php @@ -18,12 +18,12 @@ * * @implements IteratorAggregate */ -final readonly class Events implements IteratorAggregate, JsonSerializable, Countable +final class Events implements IteratorAggregate, JsonSerializable, Countable { /** * @var Event[] */ - private array $events; + private readonly array $events; private function __construct(Event ...$events) { diff --git a/src/Types/ExpectedHighestSequenceNumber.php b/src/Types/ExpectedHighestSequenceNumber.php index 476bec9..d8abf72 100644 --- a/src/Types/ExpectedHighestSequenceNumber.php +++ b/src/Types/ExpectedHighestSequenceNumber.php @@ -12,9 +12,9 @@ * Note: {@see ExpectedHighestSequenceNumber::none()} is a special case that means that _no_ event must match the specified query * Note: {@see ExpectedHighestSequenceNumber::any()} is a special case that means that the events are appended without conditions */ -final readonly class ExpectedHighestSequenceNumber +final class ExpectedHighestSequenceNumber { - private function __construct(private SequenceNumber|StreamState $sequenceNumber,) + private function __construct(private readonly SequenceNumber|StreamState $sequenceNumber) { } diff --git a/src/Types/SequenceNumber.php b/src/Types/SequenceNumber.php index 8410437..08cddd0 100644 --- a/src/Types/SequenceNumber.php +++ b/src/Types/SequenceNumber.php @@ -11,11 +11,10 @@ * * Note: The sequence number is usually not referred to in user land code, but it can be used to batch process an event stream for example */ -final readonly class SequenceNumber +final class SequenceNumber { - private function __construct( - public int $value - ) { + private function __construct(public readonly int $value) + { Assert::greaterThanEq($this->value, 1, 'sequence number has to be represented with a positive integer of at least 1, given: %d'); } diff --git a/src/Types/StreamQuery/Criteria.php b/src/Types/StreamQuery/Criteria.php index 48370a7..103b67f 100644 --- a/src/Types/StreamQuery/Criteria.php +++ b/src/Types/StreamQuery/Criteria.php @@ -17,12 +17,12 @@ * * @implements IteratorAggregate */ -final readonly class Criteria implements IteratorAggregate, JsonSerializable +final class Criteria implements IteratorAggregate, JsonSerializable { /** * @var Criterion[] */ - private array $criteria; + private readonly array $criteria; private function __construct(Criterion ...$criteria) { diff --git a/src/Types/StreamQuery/Criteria/EventTypesAndTagsCriterion.php b/src/Types/StreamQuery/Criteria/EventTypesAndTagsCriterion.php index b736ad4..0c29be0 100644 --- a/src/Types/StreamQuery/Criteria/EventTypesAndTagsCriterion.php +++ b/src/Types/StreamQuery/Criteria/EventTypesAndTagsCriterion.php @@ -9,11 +9,11 @@ use Wwwision\DCBEventStore\Types\StreamQuery\Criterion; use Wwwision\DCBEventStore\Types\Tags; -final readonly class EventTypesAndTagsCriterion implements Criterion +final class EventTypesAndTagsCriterion implements Criterion { public function __construct( - public EventTypes $eventTypes, - public Tags $tags, + public readonly EventTypes $eventTypes, + public readonly Tags $tags, ) { } diff --git a/src/Types/StreamQuery/Criteria/EventTypesCriterion.php b/src/Types/StreamQuery/Criteria/EventTypesCriterion.php index 84b3a2c..79acab1 100644 --- a/src/Types/StreamQuery/Criteria/EventTypesCriterion.php +++ b/src/Types/StreamQuery/Criteria/EventTypesCriterion.php @@ -8,10 +8,10 @@ use Wwwision\DCBEventStore\Types\EventTypes; use Wwwision\DCBEventStore\Types\StreamQuery\Criterion; -final readonly class EventTypesCriterion implements Criterion +final class EventTypesCriterion implements Criterion { public function __construct( - public EventTypes $eventTypes, + public readonly EventTypes $eventTypes, ) { } diff --git a/src/Types/StreamQuery/Criteria/TagsCriterion.php b/src/Types/StreamQuery/Criteria/TagsCriterion.php index f16fefd..1365e2d 100644 --- a/src/Types/StreamQuery/Criteria/TagsCriterion.php +++ b/src/Types/StreamQuery/Criteria/TagsCriterion.php @@ -8,10 +8,10 @@ use Wwwision\DCBEventStore\Types\StreamQuery\Criterion; use Wwwision\DCBEventStore\Types\Tags; -final readonly class TagsCriterion implements Criterion +final class TagsCriterion implements Criterion { public function __construct( - public Tags $tags, + public readonly Tags $tags, ) { } diff --git a/src/Types/StreamQuery/StreamQuery.php b/src/Types/StreamQuery/StreamQuery.php index b40ed21..677609f 100644 --- a/src/Types/StreamQuery/StreamQuery.php +++ b/src/Types/StreamQuery/StreamQuery.php @@ -11,12 +11,12 @@ /** * A Query describing events by their {@see Tags} and/or {@see EventTypes} */ -final readonly class StreamQuery +final class StreamQuery { public const VERSION = '1.0'; private function __construct( - public Criteria $criteria, + public readonly Criteria $criteria, ) { } diff --git a/src/Types/StreamQuery/StreamQuerySerializer.php b/src/Types/StreamQuery/StreamQuerySerializer.php index b75e290..4d53c7d 100644 --- a/src/Types/StreamQuery/StreamQuerySerializer.php +++ b/src/Types/StreamQuery/StreamQuerySerializer.php @@ -23,8 +23,12 @@ use const JSON_PRETTY_PRINT; -final readonly class StreamQuerySerializer +final class StreamQuerySerializer { + private function __construct() + { + } + public static function serialize(StreamQuery $streamQuery): string { $array = [ diff --git a/src/Types/Tag.php b/src/Types/Tag.php index e0fd7c7..1ca10c0 100644 --- a/src/Types/Tag.php +++ b/src/Types/Tag.php @@ -12,11 +12,11 @@ /** * Tag that can be attached to an {@see Event}, usually containing some identifier for an entity or concept of the core domain */ -final readonly class Tag implements JsonSerializable +final class Tag implements JsonSerializable { private function __construct( - public string $key, - public string $value, + public readonly string $key, + public readonly string $value, ) { Assert::regex($key, '/^[[:alnum:]\-\_]{1,50}$/', 'tag keys must only alphanumeric characters, underscores and dashes and must be between 1 and 50 characters long, given: %s'); Assert::regex($value, '/^[[:alnum:]\-\_]{1,50}$/', 'tag values must only alphanumeric characters, underscores and dashes and must be between 1 and 50 characters long, given: %s'); diff --git a/src/Types/Tags.php b/src/Types/Tags.php index 2f9a191..ee68e5f 100644 --- a/src/Types/Tags.php +++ b/src/Types/Tags.php @@ -21,12 +21,12 @@ * * @implements IteratorAggregate */ -final readonly class Tags implements IteratorAggregate, JsonSerializable +final class Tags implements IteratorAggregate, JsonSerializable { /** * @param array $tags */ - private function __construct(private array $tags) + private function __construct(private readonly array $tags) { Assert::notEmpty($this->tags, 'Tags must not be empty'); }