@@ -111,7 +111,7 @@ from this source stream.
111111The event receives a single mixed argument for incoming data.
112112
113113``` php
114- $stream->on('data', function ($data) {
114+ $stream->on('data', function (mixed $data): void {
115115 echo $data;
116116});
117117```
@@ -142,7 +142,7 @@ The `end` event will be emitted once the source stream has successfully
142142reached the end of the stream (EOF).
143143
144144``` php
145- $stream->on('end', function () {
145+ $stream->on('end', function (): void {
146146 echo 'END';
147147});
148148```
@@ -180,7 +180,7 @@ trying to read from this stream.
180180The event receives a single ` Exception ` argument for the error instance.
181181
182182``` php
183- $server->on('error', function (Exception $e) {
183+ $server->on('error', function (Exception $e): void {
184184 echo 'Error: ' . $e->getMessage() . PHP_EOL;
185185});
186186```
@@ -213,7 +213,7 @@ stream which should result in the same error processing.
213213The ` close ` event will be emitted once the stream closes (terminates).
214214
215215``` php
216- $stream->on('close', function () {
216+ $stream->on('close', function (): void {
217217 echo 'CLOSED';
218218});
219219```
@@ -312,7 +312,7 @@ Re-attach the data source after a previous `pause()`.
312312``` php
313313$stream->pause();
314314
315- Loop::addTimer(1.0, function () use ($stream) {
315+ Loop::addTimer(1.0, function () use ($stream): void {
316316 $stream->resume();
317317});
318318```
@@ -362,7 +362,7 @@ you'll have to manually close the destination stream:
362362
363363``` php
364364$source->pipe($dest);
365- $source->on('close', function () use ($dest) {
365+ $source->on('close', function () use ($dest): void {
366366 $dest->end('BYE!');
367367});
368368```
@@ -456,7 +456,7 @@ The `drain` event will be emitted whenever the write buffer became full
456456previously and is now ready to accept more data.
457457
458458``` php
459- $stream->on('drain', function () use ($stream) {
459+ $stream->on('drain', function () use ($stream): void {
460460 echo 'Stream is now ready to accept more data';
461461});
462462```
@@ -478,11 +478,11 @@ The event receives a single `ReadableStreamInterface` argument for the
478478source stream.
479479
480480``` php
481- $stream->on('pipe', function (ReadableStreamInterface $source) use ($stream) {
481+ $stream->on('pipe', function (ReadableStreamInterface $source) use ($stream): void {
482482 echo 'Now receiving piped data';
483483
484484 // explicitly close target if source emits an error
485- $source->on('error', function () use ($stream) {
485+ $source->on('error', function () use ($stream): void {
486486 $stream->close();
487487 });
488488});
@@ -506,7 +506,7 @@ trying to write to this stream.
506506The event receives a single ` Exception ` argument for the error instance.
507507
508508``` php
509- $stream->on('error', function (Exception $e) {
509+ $stream->on('error', function (Exception $e): void {
510510 echo 'Error: ' . $e->getMessage() . PHP_EOL;
511511});
512512```
@@ -536,7 +536,7 @@ stream which should result in the same error processing.
536536The ` close ` event will be emitted once the stream closes (terminates).
537537
538538``` php
539- $stream->on('close', function () {
539+ $stream->on('close', function (): void {
540540 echo 'CLOSED';
541541});
542542```
@@ -746,7 +746,7 @@ stream in order to stop waiting for the stream to flush its final data.
746746
747747``` php
748748$stream->end();
749- Loop::addTimer(1.0, function () use ($stream) {
749+ Loop::addTimer(1.0, function () use ($stream): void {
750750 $stream->close();
751751});
752752```
@@ -831,10 +831,10 @@ readable mode or a stream such as `STDIN`:
831831
832832``` php
833833$stream = new ReadableResourceStream(STDIN);
834- $stream->on('data', function ($chunk) {
834+ $stream->on('data', function (string $chunk): void {
835835 echo $chunk;
836836});
837- $stream->on('end', function () {
837+ $stream->on('end', function (): void {
838838 echo 'END';
839839});
840840```
@@ -1121,7 +1121,7 @@ used to convert data, for example for transforming any structured data into
11211121a newline-delimited JSON (NDJSON) stream like this:
11221122
11231123``` php
1124- $through = new ThroughStream(function ($data) {
1124+ $through = new ThroughStream(function (mixed $data): string {
11251125 return json_encode($data) . PHP_EOL;
11261126});
11271127$through->on('data', $this->expectCallableOnceWith("[2, true]\n"));
@@ -1133,7 +1133,7 @@ The callback function is allowed to throw an `Exception`. In this case,
11331133the stream will emit an ` error ` event and then [ ` close() ` ] ( #close-1 ) the stream.
11341134
11351135``` php
1136- $through = new ThroughStream(function ($data) {
1136+ $through = new ThroughStream(function (mixed $data): string {
11371137 if (!is_string($data)) {
11381138 throw new \UnexpectedValueException('Only strings allowed');
11391139 }
@@ -1164,7 +1164,7 @@ $stdout = new WritableResourceStream(STDOUT);
11641164
11651165$stdio = new CompositeStream($stdin, $stdout);
11661166
1167- $stdio->on('data', function ($chunk) use ($stdio) {
1167+ $stdio->on('data', function (string $chunk) use ($stdio): void {
11681168 $stdio->write('You said: ' . $chunk);
11691169});
11701170```
@@ -1243,6 +1243,12 @@ If you do not want to run these, they can simply be skipped like this:
12431243vendor/bin/phpunit --exclude-group internet
12441244```
12451245
1246+ On top of this, we use PHPStan on max level to ensure type safety across the project:
1247+
1248+ ``` bash
1249+ vendor/bin/phpstan
1250+ ```
1251+
12461252## License
12471253
12481254MIT, see [ LICENSE file] ( LICENSE ) .
0 commit comments