Skip to content

Commit 49c7b03

Browse files
committed
fix phpstan errors
1 parent cfc912c commit 49c7b03

File tree

6 files changed

+189
-48
lines changed

6 files changed

+189
-48
lines changed

baseline.xml

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.12.0@cf420941d061a57050b6c468ef2c778faf40aee2">
2+
<files psalm-version="6.13.1@1e3b7f0a8ab32b23197b91107adc0a7ed8a05b51">
33
<file src="src/Aggregate/AggregateRootBehaviour.php">
44
<UnsafeInstantiation>
55
<code><![CDATA[new static()]]></code>
@@ -29,6 +29,31 @@
2929
<code><![CDATA[base64_decode($result['crypto_iv'])]]></code>
3030
<code><![CDATA[base64_decode($result['crypto_key'])]]></code>
3131
</ArgumentTypeCoercion>
32+
<DeprecatedMethod>
33+
<code><![CDATA[setPrimaryKey]]></code>
34+
</DeprecatedMethod>
35+
</file>
36+
<file src="src/DCB/AttributeEventTagExtractor.php">
37+
<RiskyTruthyFalsyComparison>
38+
<code><![CDATA[$attribute->hash]]></code>
39+
<code><![CDATA[$attribute->prefix]]></code>
40+
</RiskyTruthyFalsyComparison>
41+
</file>
42+
<file src="src/DCB/CompositeProjection.php">
43+
<MissingClosureReturnType>
44+
<code><![CDATA[static function (Projection $projection) {]]></code>
45+
</MissingClosureReturnType>
46+
<MixedAssignment>
47+
<code><![CDATA[$state[$name]]]></code>
48+
</MixedAssignment>
49+
</file>
50+
<file src="src/DCB/DecisionModel.php">
51+
<ImplementedReturnTypeMismatch>
52+
<code><![CDATA[T[TKey]]]></code>
53+
</ImplementedReturnTypeMismatch>
54+
<InvalidCast>
55+
<code><![CDATA[$offset]]></code>
56+
</InvalidCast>
3257
</file>
3358
<file src="src/EventBus/AttributeListenerProvider.php">
3459
<MixedMethodCall>
@@ -92,6 +117,12 @@
92117
<code><![CDATA[archive]]></code>
93118
</UndefinedInterfaceMethod>
94119
</file>
120+
<file src="src/Schema/DoctrineSchemaDirector.php">
121+
<InternalMethod>
122+
<code><![CDATA[getName]]></code>
123+
<code><![CDATA[getName]]></code>
124+
</InternalMethod>
125+
</file>
95126
<file src="src/Serializer/Normalizer/IdNormalizer.php">
96127
<DeprecatedClass>
97128
<code><![CDATA[ReflectionTypeUtil::classStringInstanceOf(
@@ -103,6 +134,11 @@
103134
<code><![CDATA[IdNormalizer]]></code>
104135
</DeprecatedInterface>
105136
</file>
137+
<file src="src/Serializer/Normalizer/StringableNormalizer.php">
138+
<PropertyTypeCoercion>
139+
<code><![CDATA[$type->getClassName()]]></code>
140+
</PropertyTypeCoercion>
141+
</file>
106142
<file src="src/Serializer/Upcast/Upcast.php">
107143
<MixedAssignment>
108144
<code><![CDATA[$payload[$key]]]></code>
@@ -131,6 +167,11 @@
131167
<code><![CDATA[$streamName]]></code>
132168
</PropertyTypeCoercion>
133169
</file>
170+
<file src="src/Store/DoctrineDbalStore.php">
171+
<DeprecatedMethod>
172+
<code><![CDATA[setPrimaryKey]]></code>
173+
</DeprecatedMethod>
174+
</file>
134175
<file src="src/Store/DoctrineDbalStoreStream.php">
135176
<ArgumentTypeCoercion>
136177
<code><![CDATA[(int)$data['playhead']]]></code>
@@ -144,11 +185,33 @@
144185
<code><![CDATA[$this->messages]]></code>
145186
</MixedPropertyTypeCoercion>
146187
</file>
188+
<file src="src/Store/StreamDoctrineDbalStore.php">
189+
<DeprecatedMethod>
190+
<code><![CDATA[setPrimaryKey]]></code>
191+
</DeprecatedMethod>
192+
</file>
147193
<file src="src/Store/StreamDoctrineDbalStoreStream.php">
148194
<ArgumentTypeCoercion>
149195
<code><![CDATA[(int)$data['playhead']]]></code>
150196
</ArgumentTypeCoercion>
151197
</file>
198+
<file src="src/Store/TaggableDoctrineDbalStore.php">
199+
<MixedAssignment>
200+
<code><![CDATA[$counter]]></code>
201+
</MixedAssignment>
202+
<MixedOperand>
203+
<code><![CDATA[$counter]]></code>
204+
<code><![CDATA[$counter]]></code>
205+
</MixedOperand>
206+
</file>
207+
<file src="src/Store/TaggableDoctrineDbalStoreStream.php">
208+
<ArgumentTypeCoercion>
209+
<code><![CDATA[(int)$data['playhead']]]></code>
210+
</ArgumentTypeCoercion>
211+
<MixedArgument>
212+
<code><![CDATA[json_decode($data['tags'], true, 512, JSON_THROW_ON_ERROR)]]></code>
213+
</MixedArgument>
214+
</file>
152215
<file src="src/Subscription/Engine/DefaultSubscriptionEngine.php">
153216
<DeprecatedInterface>
154217
<code><![CDATA[SubscriberAccessor|null]]></code>
@@ -179,6 +242,9 @@
179242
</InvalidOperand>
180243
</file>
181244
<file src="src/Subscription/Store/DoctrineSubscriptionStore.php">
245+
<DeprecatedMethod>
246+
<code><![CDATA[setPrimaryKey]]></code>
247+
</DeprecatedMethod>
182248
<MixedArgument>
183249
<code><![CDATA[$context]]></code>
184250
</MixedArgument>

phpstan-baseline.neon

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,36 @@ parameters:
132132
count: 1
133133
path: src/Store/StreamDoctrineDbalStoreStream.php
134134

135+
-
136+
message: '#^Cannot use \+\+ on mixed\.$#'
137+
identifier: preInc.type
138+
count: 1
139+
path: src/Store/TaggableDoctrineDbalStore.php
140+
141+
-
142+
message: '#^Method Patchlevel\\EventSourcing\\Store\\TaggableDoctrineDbalStoreStream\:\:current\(\) never returns null so it can be removed from the return type\.$#'
143+
identifier: return.unusedType
144+
count: 1
145+
path: src/Store/TaggableDoctrineDbalStoreStream.php
146+
147+
-
148+
message: '#^Parameter \#1 \$playhead of class Patchlevel\\EventSourcing\\Store\\Header\\PlayheadHeader constructor expects int\<1, max\>, int given\.$#'
149+
identifier: argument.type
150+
count: 1
151+
path: src/Store/TaggableDoctrineDbalStoreStream.php
152+
153+
-
154+
message: '#^Parameter \#1 \$tags of class Patchlevel\\EventSourcing\\Store\\Header\\TagsHeader constructor expects list\<string\>, mixed given\.$#'
155+
identifier: argument.type
156+
count: 1
157+
path: src/Store/TaggableDoctrineDbalStoreStream.php
158+
159+
-
160+
message: '#^Ternary operator condition is always true\.$#'
161+
identifier: ternary.alwaysTrue
162+
count: 1
163+
path: src/Store/TaggableDoctrineDbalStoreStream.php
164+
135165
-
136166
message: '#^Generator expects key type int, int\<1, max\>\|null given\.$#'
137167
identifier: generator.keyType

tests/Integration/DynamicConsistencyBoundary/DynamicConsistencyBoundaryTest.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,36 @@
99
use Patchlevel\EventSourcing\CommandBus\SyncCommandBus;
1010
use Patchlevel\EventSourcing\DCB\StoreDecisionModelBuilder;
1111
use Patchlevel\EventSourcing\DCB\StoreEventAppender;
12+
use Patchlevel\EventSourcing\Message\Message;
1213
use Patchlevel\EventSourcing\Metadata\Event\AttributeEventRegistryFactory;
1314
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
1415
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
16+
use Patchlevel\EventSourcing\Store\Header\StreamNameHeader;
1517
use Patchlevel\EventSourcing\Store\TaggableDoctrineDbalStore;
1618
use Patchlevel\EventSourcing\Tests\DbalManager;
1719
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Command\ChangeCourseCapacity;
1820
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Command\DefineCourse;
1921
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Command\SubscribeStudentToCourse;
2022
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\CourseId;
23+
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Event\CourseCapacityChanged;
24+
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Event\CourseDefined;
25+
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Event\StudentSubscribedToCourse;
2126
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Handler\ChangeCourseCapacityHandler;
2227
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Handler\DefineCourseHandler;
2328
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\Handler\SubscribeStudentToCourseHandler;
2429
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Course\StudentId;
2530
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Invoice\Command\CreateInvoice;
31+
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Invoice\Event\InvoiceCreated;
2632
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Invoice\Handler\CreateInvoiceHandler;
33+
use Patchlevel\EventSourcing\Tests\PhpunitHelper;
2734
use PHPUnit\Framework\Attributes\CoversNothing;
2835
use PHPUnit\Framework\TestCase;
2936

3037
#[CoversNothing]
3138
final class DynamicConsistencyBoundaryTest extends TestCase
3239
{
40+
use PhpunitHelper;
41+
3342
private Connection $connection;
3443

3544
public function setUp(): void
@@ -77,9 +86,16 @@ public function testCourse(): void
7786
$commandBus->dispatch(new SubscribeStudentToCourse($student1Id, $courseId));
7887
$commandBus->dispatch(new SubscribeStudentToCourse($student2Id, $courseId));
7988

80-
$stream = $store->load();
81-
82-
$this->assertTrue(true);
89+
self::assertStreamEquals([
90+
Message::create(new CourseDefined($courseId, 10))
91+
->withHeader(new StreamNameHeader('main')),
92+
Message::create(new CourseCapacityChanged($courseId, 2))
93+
->withHeader(new StreamNameHeader('main')),
94+
Message::create(new StudentSubscribedToCourse($student1Id, $courseId))
95+
->withHeader(new StreamNameHeader('main')),
96+
Message::create(new StudentSubscribedToCourse($student2Id, $courseId))
97+
->withHeader(new StreamNameHeader('main')),
98+
], $store->load());
8399
}
84100

85101
public function testInvoice(): void
@@ -112,6 +128,17 @@ public function testInvoice(): void
112128
$commandBus->dispatch(new CreateInvoice(10));
113129
$commandBus->dispatch(new CreateInvoice(10));
114130

115-
$this->assertTrue(true);
131+
self::assertStreamEquals([
132+
Message::create(new InvoiceCreated(1, 10))
133+
->withHeader(new StreamNameHeader('main')),
134+
Message::create(new InvoiceCreated(2, 10))
135+
->withHeader(new StreamNameHeader('main')),
136+
Message::create(new InvoiceCreated(3, 10))
137+
->withHeader(new StreamNameHeader('main')),
138+
Message::create(new InvoiceCreated(4, 10))
139+
->withHeader(new StreamNameHeader('main')),
140+
Message::create(new InvoiceCreated(5, 10))
141+
->withHeader(new StreamNameHeader('main')),
142+
], $store->load());
116143
}
117144
}

tests/Integration/DynamicConsistencyBoundary/Invoice/Projection/NextInvoiceNumberProjection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Invoice\Projection;
66

7+
use Patchlevel\EventSourcing\Attribute\Apply;
78
use Patchlevel\EventSourcing\DCB\EventRouter;
89
use Patchlevel\EventSourcing\DCB\Projection;
910
use Patchlevel\EventSourcing\Tests\Integration\DynamicConsistencyBoundary\Invoice\Event\InvoiceCreated;
@@ -23,6 +24,7 @@ public function initialState(): int
2324
return 1;
2425
}
2526

27+
#[Apply]
2628
public function applyInvoiceCreated(int $state, InvoiceCreated $event): int
2729
{
2830
return $state + 1;

tests/Integration/Store/TaggableDoctrineDbalStoreTest.php

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@
2424
use Patchlevel\EventSourcing\Store\Header\StreamNameHeader;
2525
use Patchlevel\EventSourcing\Store\Header\TagsHeader;
2626
use Patchlevel\EventSourcing\Store\Query;
27-
use Patchlevel\EventSourcing\Store\Stream;
2827
use Patchlevel\EventSourcing\Store\SubQuery;
2928
use Patchlevel\EventSourcing\Store\TaggableDoctrineDbalStore;
3029
use Patchlevel\EventSourcing\Store\UniqueConstraintViolation;
3130
use Patchlevel\EventSourcing\Tests\DbalManager;
3231
use Patchlevel\EventSourcing\Tests\Integration\Store\Events\ExternEvent;
3332
use Patchlevel\EventSourcing\Tests\Integration\Store\Events\ProfileCreated;
33+
use Patchlevel\EventSourcing\Tests\PhpunitHelper;
3434
use PHPUnit\Framework\Attributes\CoversNothing;
3535
use PHPUnit\Framework\TestCase;
3636
use Psr\Clock\ClockInterface;
37-
use RuntimeException;
3837

39-
use function count;
4038
use function iterator_to_array;
4139
use function json_decode;
4240
use function sprintf;
4341

4442
#[CoversNothing]
4543
final class TaggableDoctrineDbalStoreTest extends TestCase
4644
{
45+
use PhpunitHelper;
46+
4747
private Connection $connection;
4848
private TaggableDoctrineDbalStore $store;
4949

@@ -567,7 +567,7 @@ public function testAppendWithoutAppendCondition(): void
567567
];
568568

569569
$this->store->append($messages);
570-
$this->expectedStream($messages);
570+
self::assertStreamEquals($messages, $this->store->load());
571571
}
572572

573573
public function testQueryTags(): void
@@ -596,7 +596,7 @@ public function testQueryTags(): void
596596
new SubQuery(['profile:' . $profileId1->toString()]),
597597
));
598598

599-
$this->expectedStreamEquals([$message1, $message3], $stream);
599+
self::assertStreamEquals([$message1, $message3], $stream);
600600
}
601601

602602
public function testQueryEvents(): void
@@ -625,7 +625,7 @@ public function testQueryEvents(): void
625625
new SubQuery(events: [ProfileCreated::class]),
626626
));
627627

628-
$this->expectedStreamEquals([$message1, $message2], $stream);
628+
self::assertStreamEquals([$message1, $message2], $stream);
629629
}
630630

631631
public function testQueryStream(): void
@@ -655,7 +655,7 @@ public function testQueryStream(): void
655655
new SubQuery(streamName: 'baz'),
656656
));
657657

658-
$this->expectedStreamEquals([$message1, $message3], $stream);
658+
self::assertStreamEquals([$message1, $message3], $stream);
659659
}
660660

661661
public function testQueryTagAndEvent(): void
@@ -684,7 +684,7 @@ public function testQueryTagAndEvent(): void
684684
new SubQuery(['profile:' . $profileId1->toString()], [ProfileCreated::class]),
685685
));
686686

687-
$this->expectedStreamEquals([$message1], $stream);
687+
self::assertStreamEquals([$message1], $stream);
688688
}
689689

690690
public function testComplexQuery(): void
@@ -719,7 +719,7 @@ public function testComplexQuery(): void
719719
new SubQuery(streamName: 'foo'),
720720
));
721721

722-
$this->expectedStreamEquals([$message1, $message2, $message3, $message4], $stream);
722+
self::assertStreamEquals([$message1, $message2, $message3, $message4], $stream);
723723
}
724724

725725
public function testAppendRaceCondition(): void
@@ -831,7 +831,7 @@ public function testAppendWithEmptyQuery(): void
831831
),
832832
);
833833

834-
$this->expectedStream([...$messages, $message]);
834+
self::assertStreamEquals([...$messages, $message], $this->store->load());
835835
}
836836

837837
public function testStreams(): void
@@ -893,37 +893,4 @@ public function testRemove(): void
893893

894894
self::assertEquals(['foo'], $streams);
895895
}
896-
897-
/** @param list<Message> $messages */
898-
private function expectedStream(array $messages): void
899-
{
900-
$this->expectedStreamEquals($messages, $this->store->load());
901-
}
902-
903-
/** @param list<Message> $expectedMessages */
904-
private function expectedStreamEquals(array $expectedMessages, Stream $stream): void
905-
{
906-
$index = 0;
907-
908-
$messages = iterator_to_array($stream);
909-
910-
self::assertEquals(count($expectedMessages), count($messages), 'Expected and actual message count do not match');
911-
912-
foreach ($messages as $message) {
913-
$expectedMessage = $expectedMessages[$index] ?? null;
914-
915-
if ($expectedMessage === null) {
916-
throw new RuntimeException(sprintf('Expected message at index %d not found', $index));
917-
}
918-
919-
$this->assertEquals(
920-
$expectedMessage->header(StreamNameHeader::class)->streamName,
921-
$message->header(StreamNameHeader::class)->streamName,
922-
);
923-
924-
$this->assertEquals($expectedMessage->event(), $message->event());
925-
926-
++$index;
927-
}
928-
}
929896
}

0 commit comments

Comments
 (0)