Skip to content

Commit

Permalink
Prevent Call to end() on null
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 5, 2023
1 parent aa62a8a commit a5e5719
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 0 additions & 4 deletions build/baseline-7.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ parameters:
message: "#^Class PHPStan\\\\Parallel\\\\Process has an uninitialized property \\$process\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: ../src/Parallel/Process.php
-
message: "#^Class PHPStan\\\\Parallel\\\\Process has an uninitialized property \\$in\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: ../src/Parallel/Process.php
-
message: "#^Class PHPStan\\\\PhpDoc\\\\ResolvedPhpDocBlock has an uninitialized property \\$phpDocNodes\\. Give it default value or assign it in the constructor\\.$#"
count: 1
Expand Down
9 changes: 8 additions & 1 deletion src/Parallel/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Process

public \React\ChildProcess\Process $process;

private WritableStreamInterface $in;
private ?WritableStreamInterface $in = null;

/** @var resource */
private $stdOut;
Expand Down Expand Up @@ -106,6 +106,9 @@ private function cancelTimer(): void
public function request(array $data): void
{
$this->cancelTimer();
if ($this->in === null) {
throw new ShouldNotHappenException();
}
$this->in->write($data);
$this->timer = $this->loop->addTimer($this->timeoutSeconds, function (): void {
$onError = $this->onError;
Expand All @@ -124,6 +127,10 @@ public function quit(): void
$pipe->close();
}

if ($this->in === null) {
return;
}

$this->in->end();
}

Expand Down

0 comments on commit a5e5719

Please sign in to comment.