fix: psalm errors

This commit is contained in:
2026-02-15 17:01:51 +01:00
parent 6f2cb7e69d
commit dd94775d9c
11 changed files with 96 additions and 27 deletions

View File

@@ -17,9 +17,18 @@ final class Command implements Stringable
{
public readonly string $program;
/**
* @var list<string>
*/
private array $args = [];
/**
* @var array<string, string|null>
*/
private ?array $environment = null;
private bool $environmentInherit = true;
private ?string $cwd = null;
private ?StdioInterface $stdin = null;
@@ -90,7 +99,7 @@ final class Command implements Stringable
* escaped characters, word splitting, glob patterns, variable substitution,
* etc. have no effect.
*
* @param iterable<string|Stringable> $args
* @param iterable<mixed, string|Stringable> $args
*/
public function args(iterable $args): static
{
@@ -118,7 +127,7 @@ final class Command implements Stringable
*/
public function env(string $key, string|Stringable $val): static
{
$this->environment[$key] = $val;
$this->environment[$key] = (string) $val;
return $this;
}
@@ -285,13 +294,13 @@ final class Command implements Stringable
{
return $this->spawnWithDescriptorSpec([
$this->stdin instanceof StdioInterface
? $this->stdin->getDescriptionSpec(0)
? $this->stdin->getDescriptiorSpec(0)
: STDIN,
$this->stdout instanceof StdioInterface
? $this->stdout->getDescriptionSpec(1)
? $this->stdout->getDescriptiorSpec(1)
: STDOUT,
$this->stderr instanceof StdioInterface
? $this->stderr->getDescriptionSpec(2)
? $this->stderr->getDescriptiorSpec(2)
: STDERR,
]);
}
@@ -322,13 +331,13 @@ final class Command implements Stringable
{
return $this->spawnWithDescriptorSpec([
$this->stdin instanceof StdioInterface
? $this->stdin->getDescriptionSpec(0)
? $this->stdin->getDescriptiorSpec(0)
: ['pipe', 'r'],
$this->stdout instanceof StdioInterface
? $this->stdout->getDescriptionSpec(1)
? $this->stdout->getDescriptiorSpec(1)
: ['pipe', 'w'],
$this->stderr instanceof StdioInterface
? $this->stderr->getDescriptionSpec(2)
? $this->stderr->getDescriptiorSpec(2)
: ['pipe', 'w'],
])->waitWithOutput();
}
@@ -345,6 +354,8 @@ final class Command implements Stringable
* Returns the arguments that will be passed to the program.
*
* This does not include the path to the program as the first argument.
*
* @return list<string>
*/
public function getArgs(): array
{
@@ -360,6 +371,8 @@ final class Command implements Stringable
*
* Note that this output does not include environment variables inherited
* from the parent process.
*
* @return array<string, string|null>
*/
public function getEnvs(): array
{
@@ -385,6 +398,9 @@ final class Command implements Stringable
]);
}
/**
* @param array<int, resource|list<string>> $descriptorSpec
*/
private function spawnWithDescriptorSpec(array $descriptorSpec): Child
{
// Find executable if path is not absolute.
@@ -393,7 +409,7 @@ final class Command implements Stringable
$path = getenv('PATH');
if (is_string($path)) {
foreach (explode(':', $path) as $path) {
$path = $path . '/' . $program;
$path = $path . DIRECTORY_SEPARATOR . $program;
if (is_executable($path)) {
$program = $path;
break;
@@ -412,10 +428,15 @@ final class Command implements Stringable
}
}
$command = [$program];
foreach ($this->args as $arg) {
$command[] = $arg;
}
try {
set_error_handler(ChildException::handleError(...));
$proc = proc_open(
[$program, ...$this->args],
$command,
$descriptorSpec,
$pipes,
$this->cwd,