From 7db1ca377536b8279ecde27778345724136dff5b Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Fri, 19 Jul 2024 22:58:22 -0400 Subject: [PATCH 1/3] Update return types for PauseBufferStream class; return voids when method is void. --- composer.json | 3 +- src/Io/PauseBufferStream.php | 66 +++++++++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 2fe67da0..744c18c0 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.11" }, "autoload": { "psr-4": { 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; From 379db490845cb9d8cf5e7c227dfcd0f73cc269d2 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Fri, 19 Jul 2024 23:03:18 -0400 Subject: [PATCH 2/3] Update the composer.json to run PHPStan --- composer.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/composer.json b/composer.json index 744c18c0..a35672a6 100644 --- a/composer.json +++ b/composer.json @@ -54,5 +54,9 @@ "psr-4": { "React\\Tests\\Http\\": "tests/" } + }, + "scripts": { + "phpstan": "vendor/bin/phpstan analyse src", + "phpstan tests": "vendor/bin/phpstan analyse tests" } } From d3ea3eb96f4d3522a85031d99cd5360aa1375735 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Thu, 25 Jul 2024 22:17:04 -0400 Subject: [PATCH 3/3] Remove return from constructor. Add PHPStan 1.4 --- composer.json | 2 +- tests/Io/AbstractMessageTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a35672a6..7aa2a73d 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "react/async": "^4 || ^3", "react/promise-stream": "^1.4", "react/promise-timer": "^1.9", - "phpstan/phpstan": "^1.11" + "phpstan/phpstan": "^1.4" }, "autoload": { "psr-4": { 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); } }