Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass PHPStan Analysis #535

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -53,5 +54,9 @@
"psr-4": {
"React\\Tests\\Http\\": "tests/"
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse src",
"phpstan tests": "vendor/bin/phpstan analyse tests"
}
}
66 changes: 53 additions & 13 deletions src/Io/PauseBufferStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -81,7 +115,7 @@ public function pause()
$this->implicit = false;
}

public function resume()
public function resume(): void
{
if ($this->closed) {
return;
Expand All @@ -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;
Expand All @@ -139,7 +179,7 @@ public function close()
}

/** @internal */
public function handleData($data)
public function handleData($data): void
{
if ($this->paused) {
$this->dataPaused .= $data;
Expand All @@ -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;
Expand All @@ -162,7 +202,7 @@ public function handleError(\Exception $e)
}

/** @internal */
public function handleEnd()
public function handleEnd(): void
{
if ($this->paused) {
$this->endPaused = true;
Expand All @@ -176,7 +216,7 @@ public function handleEnd()
}

/** @internal */
public function handleClose()
public function handleClose(): void
{
if ($this->paused) {
$this->closePaused = true;
Expand Down
2 changes: 1 addition & 1 deletion tests/Io/AbstractMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down