@@ -38,7 +38,13 @@ final class DuplexResourceStream extends EventEmitter implements DuplexStreamInt
3838 private $ closing = false ;
3939 private $ listening = false ;
4040
41- public function __construct ($ stream , LoopInterface $ loop = null , $ readChunkSize = null , WritableStreamInterface $ buffer = null )
41+ /**
42+ * @param resource $stream
43+ * @param ?LoopInterface $loop
44+ * @param ?int $readChunkSize
45+ * @param ?WritableStreamInterface $buffer
46+ */
47+ public function __construct ($ stream , $ loop = null , $ readChunkSize = null , $ buffer = null )
4248 {
4349 if (!\is_resource ($ stream ) || \get_resource_type ($ stream ) !== "stream " ) {
4450 throw new InvalidArgumentException ('First parameter must be a valid stream resource ' );
@@ -56,6 +62,13 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
5662 throw new \RuntimeException ('Unable to set stream resource to non-blocking mode ' );
5763 }
5864
65+ if ($ loop !== null && !$ loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
66+ throw new \InvalidArgumentException ('Argument #2 ($loop) expected null|React\EventLoop\LoopInterface ' );
67+ }
68+ if ($ buffer !== null && !$ buffer instanceof WritableStreamInterface) { // manual type check to support legacy PHP < 7.1
69+ throw new \InvalidArgumentException ('Argument #4 ($buffer) expected null|React\Stream\WritableStreamInterface ' );
70+ }
71+
5972 // Use unbuffered read operations on the underlying stream resource.
6073 // Reading chunks from the stream may otherwise leave unread bytes in
6174 // PHP's stream buffers which some event loop implementations do not
0 commit comments