Skip to content

Commit

Permalink
Merge pull request #7 from bwaidelich/feature/php-81-compatibility
Browse files Browse the repository at this point in the history
FEATURE: PHP 8.1 compatibility
  • Loading branch information
bwaidelich authored Aug 3, 2023
2 parents cf0266f + 88abd2e commit 2e9cfcb
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 46 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": ">=8.2",
"php": ">=8.1",
"ramsey/uuid": "^4.7",
"psr/clock": "^1",
"webmozart/assert": "^1.11"
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/InMemoryEventStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Types/AppendCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
10 changes: 5 additions & 5 deletions src/Types/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/EventData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/Types/EventEnvelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
}
4 changes: 2 additions & 2 deletions src/Types/EventId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Types/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Types/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*
* @implements IteratorAggregate<Event>
*/
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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Types/ExpectedHighestSequenceNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
7 changes: 3 additions & 4 deletions src/Types/SequenceNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Types/StreamQuery/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*
* @implements IteratorAggregate<Criterion>
*/
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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Types/StreamQuery/Criteria/EventTypesAndTagsCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Types/StreamQuery/Criteria/EventTypesCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Types/StreamQuery/Criteria/TagsCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Types/StreamQuery/StreamQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
6 changes: 5 additions & 1 deletion src/Types/StreamQuery/StreamQuerySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
6 changes: 3 additions & 3 deletions src/Types/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/Types/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
*
* @implements IteratorAggregate<Tag>
*/
final readonly class Tags implements IteratorAggregate, JsonSerializable
final class Tags implements IteratorAggregate, JsonSerializable
{
/**
* @param array<string, Tag> $tags
*/
private function __construct(private array $tags)
private function __construct(private readonly array $tags)
{
Assert::notEmpty($this->tags, 'Tags must not be empty');
}
Expand Down

0 comments on commit 2e9cfcb

Please sign in to comment.