From ea012101e28ac67420be0b9c15b38d15fe0a3e1e Mon Sep 17 00:00:00 2001 From: David Badura Date: Sat, 7 May 2022 12:24:22 +0200 Subject: [PATCH] bump php versio to 8.1 --- .github/workflows/unit.yml | 5 +- baseline.xml | 6 +-- composer.json | 4 +- composer.lock | 54 +++++++++---------- phpstan-baseline.neon | 2 +- src/EventBus/Message.php | 12 ++--- .../AggregateRoot/AggregateRootMetadata.php | 17 +++--- .../AggregateRootPropertyMetadata.php | 9 ++-- .../AttributeAggregateRootMetadataFactory.php | 5 +- src/Metadata/Event/EventMetadata.php | 7 +-- src/Metadata/Event/EventPropertyMetadata.php | 9 ++-- .../Projection/ProjectionHandleMetadata.php | 7 +-- .../Projection/ProjectionMetadata.php | 9 ++-- src/Serializer/SerializedEvent.php | 7 +-- src/Snapshot/Snapshot.php | 8 +-- .../ProfileWithBrokenApplyIntersection.php | 13 +---- .../AttributeAggregateMetadataFactoryTest.php | 19 ++++--- 17 files changed, 79 insertions(+), 114 deletions(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index f644d3597..56d439aa4 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -21,17 +21,16 @@ jobs: - "lowest" - "highest" php-version: - - "8.0" - "8.1" operating-system: - "ubuntu-latest" - "windows-latest" include: - dependencies: "locked" - php-version: "8.0" + php-version: "8.1" operating-system: "ubuntu-latest" - dependencies: "locked" - php-version: "8.0" + php-version: "8.1" operating-system: "windows-latest" steps: diff --git a/baseline.xml b/baseline.xml index 7b7088187..065c5ae82 100644 --- a/baseline.xml +++ b/baseline.xml @@ -1,9 +1,9 @@ - - $new->headers - + + [$name => $value] + $this->headers + diff --git a/composer.json b/composer.json index b5aa09db6..6001776cb 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "php": "~8.0.0|~8.1.0", + "php": "~8.1.0", "doctrine/dbal": "^3.2.0", "psr/cache": "^2.0.0|^3.0.0", "psr/log": "^2.0.0|^3.0.0", @@ -27,7 +27,7 @@ "symfony/finder": "^4.4.34|^5.4.0|^6.0.1" }, "require-dev": { - "ext-pdo_sqlite": "~8.0.0|~8.1.0", + "ext-pdo_sqlite": "~8.1.0", "doctrine/migrations": "^3.3.2", "infection/infection": "^0.26.0", "patchlevel/coding-standard": "^1.1.1", diff --git a/composer.lock b/composer.lock index 46fca45da..24975449a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "06c76f9c192b6eaaf56376aa6da55bbe", + "content-hash": "de5c2fe538259cd7d9fb05a737dd2add", "packages": [ { "name": "doctrine/cache", @@ -1489,16 +1489,16 @@ }, { "name": "friendsofphp/proxy-manager-lts", - "version": "v1.0.11", + "version": "v1.0.12", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/proxy-manager-lts.git", - "reference": "d1eadf86d5b843c496614ef075a8f655a880f1d8" + "reference": "8419f0158715b30d4b99a5bd37c6a39671994ad7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/proxy-manager-lts/zipball/d1eadf86d5b843c496614ef075a8f655a880f1d8", - "reference": "d1eadf86d5b843c496614ef075a8f655a880f1d8", + "url": "https://api.github.com/repos/FriendsOfPHP/proxy-manager-lts/zipball/8419f0158715b30d4b99a5bd37c6a39671994ad7", + "reference": "8419f0158715b30d4b99a5bd37c6a39671994ad7", "shasum": "" }, "require": { @@ -1555,7 +1555,7 @@ ], "support": { "issues": "https://github.com/FriendsOfPHP/proxy-manager-lts/issues", - "source": "https://github.com/FriendsOfPHP/proxy-manager-lts/tree/v1.0.11" + "source": "https://github.com/FriendsOfPHP/proxy-manager-lts/tree/v1.0.12" }, "funding": [ { @@ -1567,7 +1567,7 @@ "type": "tidelift" } ], - "time": "2022-05-04T11:03:58+00:00" + "time": "2022-05-05T09:31:05+00:00" }, { "name": "infection/abstract-testframework-adapter", @@ -3060,16 +3060,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6cafed9212aa56aaa3aaf3b67c0fd1e5de53f50c" + "reference": "981cc368a216c988e862a75e526b6076987d1b50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6cafed9212aa56aaa3aaf3b67c0fd1e5de53f50c", - "reference": "6cafed9212aa56aaa3aaf3b67c0fd1e5de53f50c", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/981cc368a216c988e862a75e526b6076987d1b50", + "reference": "981cc368a216c988e862a75e526b6076987d1b50", "shasum": "" }, "require": { @@ -3098,9 +3098,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.5.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.5.1" }, - "time": "2022-05-04T07:46:54+00:00" + "time": "2022-05-05T11:32:40+00:00" }, { "name": "phpstan/phpstan", @@ -4899,32 +4899,32 @@ }, { "name": "slevomat/coding-standard", - "version": "7.1", + "version": "7.2.0", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "b521bd358b5f7a7d69e9637fd139e036d8adeb6f" + "reference": "b4f96a8beea515d2d89141b7b9ad72f526d84071" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b521bd358b5f7a7d69e9637fd139e036d8adeb6f", - "reference": "b521bd358b5f7a7d69e9637fd139e036d8adeb6f", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b4f96a8beea515d2d89141b7b9ad72f526d84071", + "reference": "b4f96a8beea515d2d89141b7b9ad72f526d84071", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.4.1", + "phpstan/phpdoc-parser": "^1.5.1", "squizlabs/php_codesniffer": "^3.6.2" }, "require-dev": { - "phing/phing": "2.17.2", + "phing/phing": "2.17.3", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.4.10|1.5.2", + "phpstan/phpstan": "1.4.10|1.6.7", "phpstan/phpstan-deprecation-rules": "1.0.0", - "phpstan/phpstan-phpunit": "1.0.0|1.1.0", - "phpstan/phpstan-strict-rules": "1.1.0", - "phpunit/phpunit": "7.5.20|8.5.21|9.5.19" + "phpstan/phpstan-phpunit": "1.0.0|1.1.1", + "phpstan/phpstan-strict-rules": "1.2.3", + "phpunit/phpunit": "7.5.20|8.5.21|9.5.20" }, "type": "phpcodesniffer-standard", "extra": { @@ -4944,7 +4944,7 @@ "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.1" + "source": "https://github.com/slevomat/coding-standard/tree/7.2.0" }, "funding": [ { @@ -4956,7 +4956,7 @@ "type": "tidelift" } ], - "time": "2022-03-29T12:44:16+00:00" + "time": "2022-05-06T10:58:42+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -6594,10 +6594,10 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "~8.0.0|~8.1.0" + "php": "~8.1.0" }, "platform-dev": { - "ext-pdo_sqlite": "~8.0.0|~8.1.0" + "ext-pdo_sqlite": "~8.1.0" }, "plugin-api-version": "2.2.0" } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ddd3ab5ee..6681b5a03 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -16,7 +16,7 @@ parameters: path: src/EventBus/Message.php - - message: "#^Property Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message\\:\\:\\$headers \\(array\\{aggregateClass\\?\\: class\\-string\\, aggregateId\\?\\: string, playhead\\?\\: int, recordedOn\\?\\: DateTimeImmutable\\}\\) does not accept non\\-empty\\-array\\\\.$#" + message: "#^Parameter \\#2 \\$headers of class Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message constructor expects array\\{aggregateClass\\?\\: class\\-string\\, aggregateId\\?\\: string, playhead\\?\\: int, recordedOn\\?\\: DateTimeImmutable\\}, non\\-empty\\-array\\ given\\.$#" count: 1 path: src/EventBus/Message.php diff --git a/src/EventBus/Message.php b/src/EventBus/Message.php index 213093f8b..263a3199c 100644 --- a/src/EventBus/Message.php +++ b/src/EventBus/Message.php @@ -19,10 +19,10 @@ final class Message public const HEADER_PLAYHEAD = 'playhead'; public const HEADER_RECORDED_ON = 'recordedOn'; - private object $event; + private readonly object $event; /** @var array{aggregateClass?: class-string, aggregateId?:string, playhead?:int, recordedOn?: DateTimeImmutable} */ - private array $headers; + private readonly array $headers; /** * @param array{aggregateClass?: class-string, aggregateId?:string, playhead?:int, recordedOn?: DateTimeImmutable} $headers @@ -90,10 +90,10 @@ public function recordedOn(): DateTimeImmutable */ public function withHeader(string $name, mixed $value): self { - $new = clone $this; - $new->headers[$name] = $value; - - return $new; + return new self( + $this->event, + [$name => $value] + $this->headers + ); } /** diff --git a/src/Metadata/AggregateRoot/AggregateRootMetadata.php b/src/Metadata/AggregateRoot/AggregateRootMetadata.php index 0aaeb9624..89ddd4b25 100644 --- a/src/Metadata/AggregateRoot/AggregateRootMetadata.php +++ b/src/Metadata/AggregateRoot/AggregateRootMetadata.php @@ -4,22 +4,19 @@ namespace Patchlevel\EventSourcing\Metadata\AggregateRoot; -/** - * @readonly - */ final class AggregateRootMetadata { public function __construct( - public string $name, + public readonly string $name, /** @var array */ - public array $applyMethods, + public readonly array $applyMethods, /** @var array */ - public array $properties, + public readonly array $properties, /** @var array */ - public array $suppressEvents, - public bool $suppressAll, - public ?string $snapshotStore, - public ?int $snapshotBatch, + public readonly array $suppressEvents, + public readonly bool $suppressAll, + public readonly ?string $snapshotStore, + public readonly ?int $snapshotBatch, ) { } } diff --git a/src/Metadata/AggregateRoot/AggregateRootPropertyMetadata.php b/src/Metadata/AggregateRoot/AggregateRootPropertyMetadata.php index 7dd7f6f00..882ab07fc 100644 --- a/src/Metadata/AggregateRoot/AggregateRootPropertyMetadata.php +++ b/src/Metadata/AggregateRoot/AggregateRootPropertyMetadata.php @@ -7,15 +7,12 @@ use Patchlevel\EventSourcing\Serializer\Hydrator\Normalizer; use ReflectionProperty; -/** - * @readonly - */ final class AggregateRootPropertyMetadata { public function __construct( - public string $fieldName, - public ReflectionProperty $reflection, - public ?Normalizer $normalizer = null + public readonly string $fieldName, + public readonly ReflectionProperty $reflection, + public readonly ?Normalizer $normalizer = null ) { } } diff --git a/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php b/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php index 0b399a581..4e5b562a0 100644 --- a/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php +++ b/src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php @@ -12,6 +12,7 @@ use Patchlevel\EventSourcing\Attribute\Snapshot; use Patchlevel\EventSourcing\Attribute\SuppressMissingApply; use ReflectionClass; +use ReflectionIntersectionType; use ReflectionMethod; use ReflectionNamedType; use ReflectionUnionType; @@ -190,11 +191,9 @@ private function getEventClassesByPropertyTypes(ReflectionMethod $method): array throw new ArgumentTypeIsMissing($methodName); } - /* needs psalm to undestand ReflectionIntersectionType if ($propertyType instanceof ReflectionIntersectionType) { - throw new RuntimeException(); + throw new ArgumentTypeIsMissing($methodName); } - */ if ($propertyType instanceof ReflectionNamedType) { $eventClasses = [$propertyType->getName()]; diff --git a/src/Metadata/Event/EventMetadata.php b/src/Metadata/Event/EventMetadata.php index 9e25d3554..dad5ceba8 100644 --- a/src/Metadata/Event/EventMetadata.php +++ b/src/Metadata/Event/EventMetadata.php @@ -4,15 +4,12 @@ namespace Patchlevel\EventSourcing\Metadata\Event; -/** - * @readonly - */ final class EventMetadata { public function __construct( - public string $name, + public readonly string $name, /** @var array */ - public array $properties = [] + public readonly array $properties = [] ) { } } diff --git a/src/Metadata/Event/EventPropertyMetadata.php b/src/Metadata/Event/EventPropertyMetadata.php index aea7c470d..38141fed2 100644 --- a/src/Metadata/Event/EventPropertyMetadata.php +++ b/src/Metadata/Event/EventPropertyMetadata.php @@ -7,15 +7,12 @@ use Patchlevel\EventSourcing\Serializer\Hydrator\Normalizer; use ReflectionProperty; -/** - * @readonly - */ final class EventPropertyMetadata { public function __construct( - public string $fieldName, - public ReflectionProperty $reflection, - public ?Normalizer $normalizer = null + public readonly string $fieldName, + public readonly ReflectionProperty $reflection, + public readonly ?Normalizer $normalizer = null ) { } } diff --git a/src/Metadata/Projection/ProjectionHandleMetadata.php b/src/Metadata/Projection/ProjectionHandleMetadata.php index bacab5a5f..45a292860 100644 --- a/src/Metadata/Projection/ProjectionHandleMetadata.php +++ b/src/Metadata/Projection/ProjectionHandleMetadata.php @@ -4,14 +4,11 @@ namespace Patchlevel\EventSourcing\Metadata\Projection; -/** - * @readonly - */ final class ProjectionHandleMetadata { public function __construct( - public string $methodName, - public bool $passMessage = false + public readonly string $methodName, + public readonly bool $passMessage = false ) { } } diff --git a/src/Metadata/Projection/ProjectionMetadata.php b/src/Metadata/Projection/ProjectionMetadata.php index 5328aa2d6..4d1c0525b 100644 --- a/src/Metadata/Projection/ProjectionMetadata.php +++ b/src/Metadata/Projection/ProjectionMetadata.php @@ -4,16 +4,13 @@ namespace Patchlevel\EventSourcing\Metadata\Projection; -/** - * @readonly - */ final class ProjectionMetadata { public function __construct( /** @var array */ - public array $handleMethods, - public ?string $createMethod = null, - public ?string $dropMethod = null + public readonly array $handleMethods, + public readonly ?string $createMethod = null, + public readonly ?string $dropMethod = null ) { } } diff --git a/src/Serializer/SerializedEvent.php b/src/Serializer/SerializedEvent.php index 8d97b30cc..0ceb3d276 100644 --- a/src/Serializer/SerializedEvent.php +++ b/src/Serializer/SerializedEvent.php @@ -4,14 +4,11 @@ namespace Patchlevel\EventSourcing\Serializer; -/** - * @readonly - */ final class SerializedEvent { public function __construct( - public string $name, - public string $payload + public readonly string $name, + public readonly string $payload ) { } } diff --git a/src/Snapshot/Snapshot.php b/src/Snapshot/Snapshot.php index 9594578e9..de9b3dc76 100644 --- a/src/Snapshot/Snapshot.php +++ b/src/Snapshot/Snapshot.php @@ -9,11 +9,11 @@ final class Snapshot { /** @var class-string */ - private string $aggregate; - private string $id; - private int $playhead; + private readonly string $aggregate; + private readonly string $id; + private readonly int $playhead; /** @var array */ - private array $payload; + private readonly array $payload; /** * @param class-string $aggregate diff --git a/tests/Unit/Fixture/ProfileWithBrokenApplyIntersection.php b/tests/Unit/Fixture/ProfileWithBrokenApplyIntersection.php index 3a3f83cc5..9a6a80534 100644 --- a/tests/Unit/Fixture/ProfileWithBrokenApplyIntersection.php +++ b/tests/Unit/Fixture/ProfileWithBrokenApplyIntersection.php @@ -2,27 +2,16 @@ declare(strict_types=1); -/* -declare(strict_types=1); - namespace Patchlevel\EventSourcing\Tests\Unit\Fixture; use Patchlevel\EventSourcing\Aggregate\AggregateRoot; use Patchlevel\EventSourcing\Attribute\Aggregate; -use Patchlevel\EventSourcing\Attribute\Apply; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyBothUsage; -// [Aggregate(ProfileWithBrokenApplyIntersection::class)] +#[Aggregate(ProfileWithBrokenApplyIntersection::class)] final class ProfileWithBrokenApplyIntersection extends AggregateRoot { - #[Apply] - protected function applyIntersection(ProfileCreated&ProfileVisited $event): void - { - } - public function aggregateRootId(): string { return self::class; } } -*/ diff --git a/tests/Unit/Metadata/Aggregate/AttributeAggregateMetadataFactoryTest.php b/tests/Unit/Metadata/Aggregate/AttributeAggregateMetadataFactoryTest.php index d9a863398..d18cb89cc 100644 --- a/tests/Unit/Metadata/Aggregate/AttributeAggregateMetadataFactoryTest.php +++ b/tests/Unit/Metadata/Aggregate/AttributeAggregateMetadataFactoryTest.php @@ -4,18 +4,21 @@ namespace Patchlevel\EventSourcing\Tests\Unit\Metadata\Aggregate; +use Patchlevel\EventSourcing\Metadata\AggregateRoot\ArgumentTypeIsMissing; use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootMetadataFactory; +use Patchlevel\EventSourcing\Metadata\AggregateRoot\DuplicateEmptyApplyAttribute; +use Patchlevel\EventSourcing\Metadata\AggregateRoot\MixedApplyAttributeUsage; use Patchlevel\EventSourcing\Tests\Unit\Fixture\MessageDeleted; use Patchlevel\EventSourcing\Tests\Unit\Fixture\NameChanged; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyBothUsage; +use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyIntersection; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyMultipleApply; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenApplyNoType; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithEmptyApply; use PHPUnit\Framework\TestCase; -use RuntimeException; class AttributeAggregateMetadataFactoryTest extends TestCase { @@ -59,30 +62,26 @@ public function testApplyWithNoEventClass(): void public function testBrokenApplyWithNoType(): void { $metadataFactory = new AttributeAggregateRootMetadataFactory(); - $this->expectException(RuntimeException::class); + $this->expectException(ArgumentTypeIsMissing::class); $metadataFactory->metadata(ProfileWithBrokenApplyNoType::class); } - /** - * @requires PHP 8.1 - */ + /** @psalm-suppress UnevaluatedCode */ public function testBrokenApplyWithIntersectionType(): void { $this->markTestSkipped('Needs Pslam to not crash on the intersection type. Should be at psalm 5.'); - /* $metadataFactory = new AttributeAggregateRootMetadataFactory(); - $this->expectException(RuntimeException::class); + $this->expectException(ArgumentTypeIsMissing::class); $metadataFactory->metadata(ProfileWithBrokenApplyIntersection::class); - */ } public function testBrokenApplyWithMultipleApply(): void { $metadataFactory = new AttributeAggregateRootMetadataFactory(); - $this->expectException(RuntimeException::class); + $this->expectException(DuplicateEmptyApplyAttribute::class); $metadataFactory->metadata(ProfileWithBrokenApplyMultipleApply::class); } @@ -90,7 +89,7 @@ public function testBrokenApplyWithMultipleApply(): void public function testBrokenApplyWithBothUsages(): void { $metadataFactory = new AttributeAggregateRootMetadataFactory(); - $this->expectException(RuntimeException::class); + $this->expectException(MixedApplyAttributeUsage::class); $metadataFactory->metadata(ProfileWithBrokenApplyBothUsage::class); }