Skip to content

Commit

Permalink
Fix new Psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jul 31, 2023
1 parent a65d3bc commit f587b63
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@
<directory name="src"/>
</errorLevel>
</MissingClosureReturnType>

<UnsupportedPropertyReferenceUsage>
<errorLevel type="suppress">
<directory name="src"/>
</errorLevel>
</UnsupportedPropertyReferenceUsage>
</issueHandlers>
</psalm>
1 change: 1 addition & 0 deletions src/Internal/Posix/PosixHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class PosixHandle extends ProcessHandle
/**
* @param resource $proc Resource from proc_open()
* @param resource $extraDataPipe Stream resource for exit code
* @param positive-int $pid
*/
public function __construct(
$proc,
Expand Down
5 changes: 4 additions & 1 deletion src/Internal/Posix/PosixRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ static function (CancelledException $e) use ($suspension, $callbackId): void {
$stdout = new ReadableResourceStream($pipes[1]);
$stderr = new ReadableResourceStream($pipes[2]);

$pid = (int) $pid;
\assert($pid > 0, 'Expected positive integer for PID');

return new ProcessContext(
new PosixHandle($proc, (int) $pid, $stdin, $extraDataPipe),
new PosixHandle($proc, $pid, $stdin, $extraDataPipe),
new ProcessStreams($stdin, $stdout, $stderr),
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Internal/ProcessHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ abstract class ProcessHandle

public readonly int $originalParentPid;

/** @psalm-suppress PropertyNotSetInConstructor */
/**
* @psalm-suppress PropertyNotSetInConstructor
* @var positive-int
*/
public int $pid;

public ProcessStatus $status = ProcessStatus::Starting;
Expand Down
7 changes: 6 additions & 1 deletion src/Internal/Windows/SocketConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,19 @@ public function performClientHandshake($socket): WindowsHandle
return $handle;
}

/**
* @return positive-int
*/
private function readChildPid(ReadableResourceStream $stream): int
{
$packet = \unpack('Csignal/Npid', $this->read($stream, 5));
if ($packet['signal'] !== SignalCode::CHILD_PID) {
throw new HandshakeException(HandshakeStatus::SIGNAL_UNEXPECTED);
}

return (int) $packet['pid'];
$pid = (int) $packet['pid'];
\assert($pid > 0, 'Expected positive integer for PID');
return $pid;
}

private function readExitCode(ReadableResourceStream $stream): int
Expand Down
2 changes: 1 addition & 1 deletion src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function getStderr(): ReadableResourceStream
* workingDirectory: string,
* environment: array<string, string>,
* options: array<string, bool>,
* pid: positive-int,
* pid: int,
* status: string,
* }
*/
Expand Down

0 comments on commit f587b63

Please sign in to comment.