Skip to content

Commit 4e76339

Browse files
committed
refactor stream
1 parent 2979470 commit 4e76339

46 files changed

Lines changed: 665 additions & 1654 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

phpstan-baseline.neon

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ parameters:
5454
count: 1
5555
path: src/Message/Serializer/DefaultHeadersSerializer.php
5656

57+
-
58+
message: '#^Property Patchlevel\\EventSourcing\\Message\\Stream\:\:\$iterator \(Iterator\<int, Patchlevel\\EventSourcing\\Message\\Message\>\|null\) does not accept IteratorIterator\<mixed, mixed, Traversable\<TKey, TValue\>\>\.$#'
59+
identifier: assign.propertyType
60+
count: 1
61+
path: src/Message/Stream.php
62+
5763
-
5864
message: '#^Property Patchlevel\\EventSourcing\\Serializer\\Normalizer\\IdNormalizer\:\:\$identifierClass \(class\-string\<Patchlevel\\EventSourcing\\Identifier\\Identifier\>\|null\) does not accept string\.$#'
5965
identifier: assign.propertyType
@@ -66,24 +72,6 @@ parameters:
6672
count: 1
6773
path: src/Snapshot/DefaultSnapshotStore.php
6874

69-
-
70-
message: '#^Method Patchlevel\\EventSourcing\\Store\\ArrayStream\:\:current\(\) never returns null so it can be removed from the return type\.$#'
71-
identifier: return.unusedType
72-
count: 1
73-
path: src/Store/ArrayStream.php
74-
75-
-
76-
message: '#^Property Patchlevel\\EventSourcing\\Store\\ArrayStream\:\:\$index \(int\<1, max\>\|null\) does not accept int\<0, max\>\.$#'
77-
identifier: assign.propertyType
78-
count: 1
79-
path: src/Store/ArrayStream.php
80-
81-
-
82-
message: '#^Ternary operator condition is always true\.$#'
83-
identifier: ternary.alwaysTrue
84-
count: 1
85-
path: src/Store/ArrayStream.php
86-
8775
-
8876
message: '#^Method Patchlevel\\EventSourcing\\Store\\Criteria\\Criteria\:\:get\(\) should return T of object but returns object\.$#'
8977
identifier: return.type
@@ -96,59 +84,23 @@ parameters:
9684
count: 1
9785
path: src/Store/Criteria/StreamCriterion.php
9886

99-
-
100-
message: '#^Method Patchlevel\\EventSourcing\\Store\\StreamDoctrineDbalStoreStream\:\:current\(\) never returns null so it can be removed from the return type\.$#'
101-
identifier: return.unusedType
102-
count: 1
103-
path: src/Store/StreamDoctrineDbalStoreStream.php
104-
10587
-
10688
message: '#^Parameter \#1 \$playhead of class Patchlevel\\EventSourcing\\Store\\Header\\PlayheadHeader constructor expects int\<1, max\>, int given\.$#'
10789
identifier: argument.type
10890
count: 1
109-
path: src/Store/StreamDoctrineDbalStoreStream.php
110-
111-
-
112-
message: '#^Ternary operator condition is always true\.$#'
113-
identifier: ternary.alwaysTrue
114-
count: 1
115-
path: src/Store/StreamDoctrineDbalStoreStream.php
116-
117-
-
118-
message: '#^Method Patchlevel\\EventSourcing\\Store\\TaggableDoctrineDbalStoreStream\:\:current\(\) never returns null so it can be removed from the return type\.$#'
119-
identifier: return.unusedType
120-
count: 1
121-
path: src/Store/TaggableDoctrineDbalStoreStream.php
91+
path: src/Store/StreamDoctrineDbalStore.php
12292

12393
-
12494
message: '#^Parameter \#1 \$playhead of class Patchlevel\\EventSourcing\\Store\\Header\\PlayheadHeader constructor expects int\<1, max\>, int given\.$#'
12595
identifier: argument.type
12696
count: 1
127-
path: src/Store/TaggableDoctrineDbalStoreStream.php
97+
path: src/Store/TaggableDoctrineDbalStore.php
12898

12999
-
130100
message: '#^Parameter \#1 \$tags of class Patchlevel\\EventSourcing\\Store\\Header\\TagsHeader constructor expects list\<string\>, mixed given\.$#'
131101
identifier: argument.type
132102
count: 1
133-
path: src/Store/TaggableDoctrineDbalStoreStream.php
134-
135-
-
136-
message: '#^Ternary operator condition is always true\.$#'
137-
identifier: ternary.alwaysTrue
138-
count: 1
139-
path: src/Store/TaggableDoctrineDbalStoreStream.php
140-
141-
-
142-
message: '#^Generator expects key type int, int\<1, max\>\|null given\.$#'
143-
identifier: generator.keyType
144-
count: 1
145-
path: src/Subscription/Engine/GapResolverStoreMessageLoader.php
146-
147-
-
148-
message: '#^Property Patchlevel\\EventSourcing\\Subscription\\Engine\\GeneratorStream\:\:\$index \(int\<1, max\>\|null\) does not accept int\.$#'
149-
identifier: assign.propertyType
150-
count: 1
151-
path: src/Subscription/Engine/GeneratorStream.php
103+
path: src/Store/TaggableDoctrineDbalStore.php
152104

153105
-
154106
message: '#^Parameter \#1 \$eventClass of method Patchlevel\\EventSourcing\\Metadata\\Event\\EventRegistry\:\:eventName\(\) expects class\-string, string given\.$#'
@@ -294,12 +246,6 @@ parameters:
294246
count: 1
295247
path: tests/Integration/Store/Profile.php
296248

297-
-
298-
message: '#^Using nullsafe method call on non\-nullable type Patchlevel\\EventSourcing\\Store\\Stream\. Use \-\> instead\.$#'
299-
identifier: nullsafe.neverNull
300-
count: 1
301-
path: tests/Integration/Store/StreamDoctrineDbalStoreTest.php
302-
303249
-
304250
message: '#^Parameter \#1 \$table of class Patchlevel\\EventSourcing\\Subscription\\Cleanup\\Dbal\\DropTableTask constructor expects non\-empty\-string, string given\.$#'
305251
identifier: argument.type

src/Console/Command/StoreMigrateCommand.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Patchlevel\EventSourcing\Console\InputHelper;
88
use Patchlevel\EventSourcing\Console\OutputStyle;
9-
use Patchlevel\EventSourcing\Message\Pipe;
109
use Patchlevel\EventSourcing\Message\Translator\Translator;
1110
use Patchlevel\EventSourcing\Store\Store;
1211
use Symfony\Component\Console\Attribute\AsCommand;
@@ -46,38 +45,23 @@ protected function configure(): void
4645

4746
protected function execute(InputInterface $input, OutputInterface $output): int
4847
{
49-
$buffer = InputHelper::positiveIntOrZero($input->getOption('buffer'));
48+
$buffer = InputHelper::positiveInt($input->getOption('buffer'));
5049
$style = new OutputStyle($input, $output);
5150

5251
$style->info('Migration initialization...');
5352

5453
$count = $this->store->count();
55-
$messages = $this->store->load();
54+
$stream = $this->store->load();
5655

5756
$style->progressStart($count);
5857

59-
$bufferedMessages = [];
58+
$translatedStream = $stream->transform(...$this->translators);
6059

61-
$pipe = new Pipe(
62-
$messages,
63-
...$this->translators,
64-
);
60+
foreach ($translatedStream->chunk($buffer) as $chunk) {
61+
$messages = $chunk->toList();
6562

66-
foreach ($pipe as $message) {
67-
$bufferedMessages[] = $message;
68-
69-
if (count($bufferedMessages) < $buffer) {
70-
continue;
71-
}
72-
73-
$this->newStore->save(...$bufferedMessages);
74-
$bufferedMessages = [];
75-
$style->progressAdvance($buffer);
76-
}
77-
78-
if (count($bufferedMessages) !== 0) {
79-
$this->newStore->save(...$bufferedMessages);
80-
$style->progressAdvance(count($bufferedMessages));
63+
$this->newStore->save(...$messages);
64+
$style->progressAdvance(count($messages));
8165
}
8266

8367
$style->progressFinish();

src/Console/InputHelper.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ public static function nullableInt(mixed $value): int|null
6666
return (int)$value;
6767
}
6868

69+
/** @return positive-int */
70+
public static function positiveInt(mixed $value): int
71+
{
72+
if (!is_string($value) && !is_int($value)) {
73+
throw new InvalidArgumentGiven($value, 'positive-int');
74+
}
75+
76+
if (!is_numeric($value)) {
77+
throw new InvalidArgumentGiven($value, 'positive-int');
78+
}
79+
80+
$value = (int)$value;
81+
82+
if ($value <= 0) {
83+
throw new InvalidArgumentGiven($value, 'positive-int');
84+
}
85+
86+
return $value;
87+
}
88+
6989
/** @return positive-int|null */
7090
public static function nullablePositiveInt(mixed $value): int|null
7191
{

src/Message/Pipe.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)