diff --git a/composer.json b/composer.json index 2fe67da0..7aa2a73d 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,8 @@ "phpunit/phpunit": "^9.6 || ^7.5", "react/async": "^4 || ^3", "react/promise-stream": "^1.4", - "react/promise-timer": "^1.9" + "react/promise-timer": "^1.9", + "phpstan/phpstan": "^1.4" }, "autoload": { "psr-4": { @@ -53,5 +54,9 @@ "psr-4": { "React\\Tests\\Http\\": "tests/" } + }, + "scripts": { + "phpstan": "vendor/bin/phpstan analyse src", + "phpstan tests": "vendor/bin/phpstan analyse tests" } } diff --git a/src/Io/PauseBufferStream.php b/src/Io/PauseBufferStream.php index b1132adc..dde22412 100644 --- a/src/Io/PauseBufferStream.php +++ b/src/Io/PauseBufferStream.php @@ -23,13 +23,44 @@ */ class PauseBufferStream extends EventEmitter implements ReadableStreamInterface { + /** + * @var ReadableStreamInterface + */ private $input; + + /** + * @var bool + */ private $closed = false; + + /** + * @var bool + */ private $paused = false; + + /** + * @var string + */ private $dataPaused = ''; + + /** + * @var bool + */ private $endPaused = false; + + /** + * @var bool + */ private $closePaused = false; - private $errorPaused; + + /** + * @var bool + */ + private $errorPaused = false; + + /** + * @var bool + */ private $implicit = false; public function __construct(ReadableStreamInterface $input) @@ -65,12 +96,15 @@ public function resumeImplicit() } } - public function isReadable() + /** + * @return bool + */ + public function isReadable(): bool { return !$this->closed; } - public function pause() + public function pause(): void { if ($this->closed) { return; @@ -81,7 +115,7 @@ public function pause() $this->implicit = false; } - public function resume() + public function resume(): void { if ($this->closed) { return; @@ -97,31 +131,37 @@ public function resume() if ($this->errorPaused) { $this->emit('error', [$this->errorPaused]); - return $this->close(); + $this->close(); + return; } if ($this->endPaused) { $this->endPaused = false; $this->emit('end'); - return $this->close(); + $this->close(); + return; } if ($this->closePaused) { $this->closePaused = false; - return $this->close(); + $this->close(); + return; } $this->input->resume(); } - public function pipe(WritableStreamInterface $dest, array $options = []) + public function pipe(WritableStreamInterface $dest, array $options = []): WritableStreamInterface { Util::pipe($this, $dest, $options); return $dest; } - public function close() + /** + * @return void + */ + public function close(): void { if ($this->closed) { return; @@ -139,7 +179,7 @@ public function close() } /** @internal */ - public function handleData($data) + public function handleData($data): void { if ($this->paused) { $this->dataPaused .= $data; @@ -150,7 +190,7 @@ public function handleData($data) } /** @internal */ - public function handleError(\Exception $e) + public function handleError(\Exception $e): void { if ($this->paused) { $this->errorPaused = $e; @@ -162,7 +202,7 @@ public function handleError(\Exception $e) } /** @internal */ - public function handleEnd() + public function handleEnd(): void { if ($this->paused) { $this->endPaused = true; @@ -176,7 +216,7 @@ public function handleEnd() } /** @internal */ - public function handleClose() + public function handleClose(): void { if ($this->paused) { $this->closePaused = true; diff --git a/tests/Io/AbstractMessageTest.php b/tests/Io/AbstractMessageTest.php index 5451281a..5a961352 100644 --- a/tests/Io/AbstractMessageTest.php +++ b/tests/Io/AbstractMessageTest.php @@ -15,7 +15,7 @@ class MessageMock extends AbstractMessage */ public function __construct($protocolVersion, array $headers, StreamInterface $body) { - return parent::__construct($protocolVersion, $headers, $body); + parent::__construct($protocolVersion, $headers, $body); } }