stream
stream copied to clipboard
chore: declare return type of `pipe()` methods by `@template`
These changes allow IDEs and PHPStan to more correctly detect the type of objects returned from the React\Stream\Util::pipe() and React\Stream\ReadableStreamInterface::pipe() methods.
After applying these changes, calling chains from pipe() methods will no longer result in PHPStan errors for the following code:
$stream1 = new React\Stream\ThroughStream();
$stream2 = new React\Stream\ThroughStream();
$stream3 = new React\Stream\ThroughStream();
$stream4 = new React\Stream\ThroughStream();
$stream1
->pipe($stream2)
->pipe($stream3) // Call to an undefined method React\Stream\WritableStreamInterface::pipe().
->pipe($stream4) // Call to an undefined method React\Stream\WritableStreamInterface::pipe().
;
Also, the IDE (using PhpStorm as an example) will be able to correctly understand the object type returned from the pipe() method. The following warning will no longer appear:
Potentially polymorphic call. WritableResourceStream does not have members in its hierarchy