diff --git a/ExecutableFinder.php b/ExecutableFinder.php index 5914b4cd..2fe558be 100644 --- a/ExecutableFinder.php +++ b/ExecutableFinder.php @@ -43,10 +43,8 @@ public function addSuffix(string $suffix) * @param string $name The executable name (without the extension) * @param string|null $default The default to return if no executable is found * @param array $extraDirs Additional dirs to check into - * - * @return string|null */ - public function find(string $name, string $default = null, array $extraDirs = []) + public function find(string $name, string $default = null, array $extraDirs = []): ?string { if (ini_get('open_basedir')) { $searchPath = array_merge(explode(\PATH_SEPARATOR, ini_get('open_basedir')), $extraDirs); diff --git a/InputStream.php b/InputStream.php index 240665f3..b8682bae 100644 --- a/InputStream.php +++ b/InputStream.php @@ -41,7 +41,7 @@ public function onEmpty(callable $onEmpty = null) * @param resource|string|int|float|bool|\Traversable|null $input The input to append as scalar, * stream resource or \Traversable */ - public function write($input) + public function write(mixed $input) { if (null === $input) { return; @@ -68,11 +68,7 @@ public function isClosed() return !$this->open; } - /** - * @return \Traversable - */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): \Traversable { $this->open = true; diff --git a/PhpExecutableFinder.php b/PhpExecutableFinder.php index ec24f911..1881adaf 100644 --- a/PhpExecutableFinder.php +++ b/PhpExecutableFinder.php @@ -28,10 +28,8 @@ public function __construct() /** * Finds The PHP executable. - * - * @return string|false */ - public function find(bool $includeArgs = true) + public function find(bool $includeArgs = true): string|false { if ($php = getenv('PHP_BINARY')) { if (!is_executable($php)) { @@ -84,10 +82,8 @@ public function find(bool $includeArgs = true) /** * Finds the PHP executable arguments. - * - * @return array */ - public function findArguments() + public function findArguments(): array { $arguments = []; if ('phpdbg' === \PHP_SAPI) { diff --git a/PhpProcess.php b/PhpProcess.php index 2bc338e5..cb749f9b 100644 --- a/PhpProcess.php +++ b/PhpProcess.php @@ -53,7 +53,7 @@ public function __construct(string $script, string $cwd = null, array $env = nul /** * {@inheritdoc} */ - public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60) + public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60): static { throw new LogicException(sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class)); } diff --git a/Pipes/AbstractPipes.php b/Pipes/AbstractPipes.php index 2d145872..dca7ae7f 100644 --- a/Pipes/AbstractPipes.php +++ b/Pipes/AbstractPipes.php @@ -20,7 +20,7 @@ */ abstract class AbstractPipes implements PipesInterface { - public $pipes = []; + public array $pipes = []; private $inputBuffer = ''; private $input; @@ -30,7 +30,7 @@ abstract class AbstractPipes implements PipesInterface /** * @param resource|string|int|float|bool|\Iterator|null $input */ - public function __construct($input) + public function __construct(mixed $input) { if (\is_resource($input) || $input instanceof \Iterator) { $this->input = $input; diff --git a/Pipes/UnixPipes.php b/Pipes/UnixPipes.php index 5a0e9d47..063aa6ad 100644 --- a/Pipes/UnixPipes.php +++ b/Pipes/UnixPipes.php @@ -26,7 +26,7 @@ class UnixPipes extends AbstractPipes private $ptyMode; private $haveReadSupport; - public function __construct(?bool $ttyMode, bool $ptyMode, $input, bool $haveReadSupport) + public function __construct(?bool $ttyMode, bool $ptyMode, mixed $input, bool $haveReadSupport) { $this->ttyMode = $ttyMode; $this->ptyMode = $ptyMode; diff --git a/Pipes/WindowsPipes.php b/Pipes/WindowsPipes.php index bca84f57..e68ed951 100644 --- a/Pipes/WindowsPipes.php +++ b/Pipes/WindowsPipes.php @@ -35,7 +35,7 @@ class WindowsPipes extends AbstractPipes ]; private $haveReadSupport; - public function __construct($input, bool $haveReadSupport) + public function __construct(mixed $input, bool $haveReadSupport) { $this->haveReadSupport = $haveReadSupport; diff --git a/Process.php b/Process.php index 4d811a69..878d7f58 100644 --- a/Process.php +++ b/Process.php @@ -140,7 +140,7 @@ class Process implements \IteratorAggregate * * @throws LogicException When proc_open is not installed */ - public function __construct(array $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60) + public function __construct(array $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60) { if (!\function_exists('proc_open')) { throw new LogicException('The Process class relies on proc_open, which is not available on your PHP installation.'); @@ -185,11 +185,9 @@ public function __construct(array $command, string $cwd = null, array $env = nul * @param mixed $input The input as stream resource, scalar or \Traversable, or null for no input * @param int|float|null $timeout The timeout in seconds or null to disable * - * @return static - * * @throws LogicException When proc_open is not installed */ - public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60) + public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60): static { $process = new static([], $cwd, $env, $input, $timeout); $process->commandline = $command; @@ -197,10 +195,7 @@ public static function fromShellCommandline(string $command, string $cwd = null, return $process; } - /** - * @return array - */ - public function __sleep() + public function __sleep(): array { throw new \BadMethodCallException('Cannot serialize '.__CLASS__); } @@ -266,7 +261,7 @@ public function run(callable $callback = null, array $env = []): int * * @final */ - public function mustRun(callable $callback = null, array $env = []): self + public function mustRun(callable $callback = null, array $env = []): static { if (0 !== $this->run($callback, $env)) { throw new ProcessFailedException($this); @@ -376,8 +371,6 @@ public function start(callable $callback = null, array $env = []) * @param callable|null $callback A PHP callback to run whenever there is some * output available on STDOUT or STDERR * - * @return static - * * @throws RuntimeException When process can't be launched * @throws RuntimeException When process is already running * @@ -385,7 +378,7 @@ public function start(callable $callback = null, array $env = []) * * @final */ - public function restart(callable $callback = null, array $env = []): self + public function restart(callable $callback = null, array $env = []): static { if ($this->isRunning()) { throw new RuntimeException('Process is already running.'); @@ -412,7 +405,7 @@ public function restart(callable $callback = null, array $env = []): self * @throws ProcessSignaledException When process stopped after receiving signal * @throws LogicException When process is not yet started */ - public function wait(callable $callback = null) + public function wait(callable $callback = null): int { $this->requireProcessIsStarted(__FUNCTION__); @@ -495,7 +488,7 @@ public function waitUntil(callable $callback): bool * * @return int|null The process id if running, null otherwise */ - public function getPid() + public function getPid(): ?int { return $this->isRunning() ? $this->processInformation['pid'] : null; } @@ -511,7 +504,7 @@ public function getPid() * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed * @throws RuntimeException In case of failure */ - public function signal(int $signal) + public function signal(int $signal): static { $this->doSignal($signal, true); @@ -526,7 +519,7 @@ public function signal(int $signal) * @throws RuntimeException In case the process is already running * @throws LogicException if an idle timeout is set */ - public function disableOutput() + public function disableOutput(): static { if ($this->isRunning()) { throw new RuntimeException('Disabling output while the process is running is not possible.'); @@ -547,7 +540,7 @@ public function disableOutput() * * @throws RuntimeException In case the process is already running */ - public function enableOutput() + public function enableOutput(): static { if ($this->isRunning()) { throw new RuntimeException('Enabling output while the process is running is not possible.'); @@ -560,10 +553,8 @@ public function enableOutput() /** * Returns true in case the output is disabled, false otherwise. - * - * @return bool */ - public function isOutputDisabled() + public function isOutputDisabled(): bool { return $this->outputDisabled; } @@ -571,12 +562,10 @@ public function isOutputDisabled() /** * Returns the current output of the process (STDOUT). * - * @return string - * * @throws LogicException in case the output has been disabled * @throws LogicException In case the process is not started */ - public function getOutput() + public function getOutput(): string { $this->readPipesForOutput(__FUNCTION__); @@ -593,12 +582,10 @@ public function getOutput() * In comparison with the getOutput method which always return the whole * output, this one returns the new output since the last call. * - * @return string - * * @throws LogicException in case the output has been disabled * @throws LogicException In case the process is not started */ - public function getIncrementalOutput() + public function getIncrementalOutput(): string { $this->readPipesForOutput(__FUNCTION__); @@ -619,11 +606,8 @@ public function getIncrementalOutput() * * @throws LogicException in case the output has been disabled * @throws LogicException In case the process is not started - * - * @return \Generator */ - #[\ReturnTypeWillChange] - public function getIterator(int $flags = 0) + public function getIterator(int $flags = 0): \Generator { $this->readPipesForOutput(__FUNCTION__, false); @@ -675,7 +659,7 @@ public function getIterator(int $flags = 0) * * @return $this */ - public function clearOutput() + public function clearOutput(): static { ftruncate($this->stdout, 0); fseek($this->stdout, 0); @@ -687,12 +671,10 @@ public function clearOutput() /** * Returns the current error output of the process (STDERR). * - * @return string - * * @throws LogicException in case the output has been disabled * @throws LogicException In case the process is not started */ - public function getErrorOutput() + public function getErrorOutput(): string { $this->readPipesForOutput(__FUNCTION__); @@ -710,12 +692,10 @@ public function getErrorOutput() * whole error output, this one returns the new error output since the last * call. * - * @return string - * * @throws LogicException in case the output has been disabled * @throws LogicException In case the process is not started */ - public function getIncrementalErrorOutput() + public function getIncrementalErrorOutput(): string { $this->readPipesForOutput(__FUNCTION__); @@ -734,7 +714,7 @@ public function getIncrementalErrorOutput() * * @return $this */ - public function clearErrorOutput() + public function clearErrorOutput(): static { ftruncate($this->stderr, 0); fseek($this->stderr, 0); @@ -748,7 +728,7 @@ public function clearErrorOutput() * * @return int|null The exit status code, null if the Process is not terminated */ - public function getExitCode() + public function getExitCode(): ?int { $this->updateStatus(false); @@ -766,7 +746,7 @@ public function getExitCode() * @see http://tldp.org/LDP/abs/html/exitcodes.html * @see http://en.wikipedia.org/wiki/Unix_signal */ - public function getExitCodeText() + public function getExitCodeText(): ?string { if (null === $exitcode = $this->getExitCode()) { return null; @@ -777,10 +757,8 @@ public function getExitCodeText() /** * Checks if the process ended successfully. - * - * @return bool */ - public function isSuccessful() + public function isSuccessful(): bool { return 0 === $this->getExitCode(); } @@ -790,11 +768,9 @@ public function isSuccessful() * * It always returns false on Windows. * - * @return bool - * * @throws LogicException In case the process is not terminated */ - public function hasBeenSignaled() + public function hasBeenSignaled(): bool { $this->requireProcessIsTerminated(__FUNCTION__); @@ -806,12 +782,10 @@ public function hasBeenSignaled() * * It is only meaningful if hasBeenSignaled() returns true. * - * @return int - * * @throws RuntimeException In case --enable-sigchild is activated * @throws LogicException In case the process is not terminated */ - public function getTermSignal() + public function getTermSignal(): int { $this->requireProcessIsTerminated(__FUNCTION__); @@ -827,11 +801,9 @@ public function getTermSignal() * * It always returns false on Windows. * - * @return bool - * * @throws LogicException In case the process is not terminated */ - public function hasBeenStopped() + public function hasBeenStopped(): bool { $this->requireProcessIsTerminated(__FUNCTION__); @@ -843,11 +815,9 @@ public function hasBeenStopped() * * It is only meaningful if hasBeenStopped() returns true. * - * @return int - * * @throws LogicException In case the process is not terminated */ - public function getStopSignal() + public function getStopSignal(): int { $this->requireProcessIsTerminated(__FUNCTION__); @@ -856,10 +826,8 @@ public function getStopSignal() /** * Checks if the process is currently running. - * - * @return bool */ - public function isRunning() + public function isRunning(): bool { if (self::STATUS_STARTED !== $this->status) { return false; @@ -872,20 +840,16 @@ public function isRunning() /** * Checks if the process has been started with no regard to the current state. - * - * @return bool */ - public function isStarted() + public function isStarted(): bool { return self::STATUS_READY != $this->status; } /** * Checks if the process is terminated. - * - * @return bool */ - public function isTerminated() + public function isTerminated(): bool { $this->updateStatus(false); @@ -896,10 +860,8 @@ public function isTerminated() * Gets the process status. * * The status is one of: ready, started, terminated. - * - * @return string */ - public function getStatus() + public function getStatus(): string { $this->updateStatus(false); @@ -914,7 +876,7 @@ public function getStatus() * * @return int|null The exit-code of the process or null if it's not running */ - public function stop(float $timeout = 10, int $signal = null) + public function stop(float $timeout = 10, int $signal = null): ?int { $timeoutMicro = microtime(true) + $timeout; if ($this->isRunning()) { @@ -973,8 +935,6 @@ public function addErrorOutput(string $line) /** * Gets the last output time in seconds. - * - * @return float|null */ public function getLastOutputTime(): ?float { @@ -983,30 +943,24 @@ public function getLastOutputTime(): ?float /** * Gets the command line to be executed. - * - * @return string */ - public function getCommandLine() + public function getCommandLine(): string { return \is_array($this->commandline) ? implode(' ', array_map([$this, 'escapeArgument'], $this->commandline)) : $this->commandline; } /** * Gets the process timeout in seconds (max. runtime). - * - * @return float|null */ - public function getTimeout() + public function getTimeout(): ?float { return $this->timeout; } /** * Gets the process idle timeout in seconds (max. time since last output). - * - * @return float|null */ - public function getIdleTimeout() + public function getIdleTimeout(): ?float { return $this->idleTimeout; } @@ -1020,7 +974,7 @@ public function getIdleTimeout() * * @throws InvalidArgumentException if the timeout is negative */ - public function setTimeout(?float $timeout) + public function setTimeout(?float $timeout): static { $this->timeout = $this->validateTimeout($timeout); @@ -1037,7 +991,7 @@ public function setTimeout(?float $timeout) * @throws LogicException if the output is disabled * @throws InvalidArgumentException if the timeout is negative */ - public function setIdleTimeout(?float $timeout) + public function setIdleTimeout(?float $timeout): static { if (null !== $timeout && $this->outputDisabled) { throw new LogicException('Idle timeout cannot be set while the output is disabled.'); @@ -1055,7 +1009,7 @@ public function setIdleTimeout(?float $timeout) * * @throws RuntimeException In case the TTY mode is not supported */ - public function setTty(bool $tty) + public function setTty(bool $tty): static { if ('\\' === \DIRECTORY_SEPARATOR && $tty) { throw new RuntimeException('TTY mode is not supported on Windows platform.'); @@ -1072,10 +1026,8 @@ public function setTty(bool $tty) /** * Checks if the TTY mode is enabled. - * - * @return bool */ - public function isTty() + public function isTty(): bool { return $this->tty; } @@ -1085,7 +1037,7 @@ public function isTty() * * @return $this */ - public function setPty(bool $bool) + public function setPty(bool $bool): static { $this->pty = $bool; @@ -1094,20 +1046,16 @@ public function setPty(bool $bool) /** * Returns PTY state. - * - * @return bool */ - public function isPty() + public function isPty(): bool { return $this->pty; } /** * Gets the working directory. - * - * @return string|null */ - public function getWorkingDirectory() + public function getWorkingDirectory(): ?string { if (null === $this->cwd) { // getcwd() will return false if any one of the parent directories does not have @@ -1123,7 +1071,7 @@ public function getWorkingDirectory() * * @return $this */ - public function setWorkingDirectory(string $cwd) + public function setWorkingDirectory(string $cwd): static { $this->cwd = $cwd; @@ -1132,10 +1080,8 @@ public function setWorkingDirectory(string $cwd) /** * Gets the environment variables. - * - * @return array */ - public function getEnv() + public function getEnv(): array { return $this->env; } @@ -1147,7 +1093,7 @@ public function getEnv() * * @return $this */ - public function setEnv(array $env) + public function setEnv(array $env): static { $this->env = $env; @@ -1175,7 +1121,7 @@ public function getInput() * * @throws LogicException In case the process is running */ - public function setInput($input) + public function setInput(mixed $input): static { if ($this->isRunning()) { throw new LogicException('Input cannot be set while the process is running.'); @@ -1267,10 +1213,8 @@ public static function isTtySupported(): bool /** * Returns whether PTY is supported on the current operating system. - * - * @return bool */ - public static function isPtySupported() + public static function isPtySupported(): bool { static $result; @@ -1309,10 +1253,8 @@ private function getDescriptors(): array * the user callback (if present) with the received output. * * @param callable|null $callback The user defined PHP callback - * - * @return \Closure */ - protected function buildCallback(callable $callback = null) + protected function buildCallback(callable $callback = null): \Closure { if ($this->outputDisabled) { return function ($type, $data) use ($callback): bool { @@ -1360,10 +1302,8 @@ protected function updateStatus(bool $blocking) /** * Returns whether PHP has been compiled with the '--enable-sigchild' option or not. - * - * @return bool */ - protected function isSigchildEnabled() + protected function isSigchildEnabled(): bool { if (null !== self::$sigchild) { return self::$sigchild; @@ -1493,8 +1433,6 @@ private function resetProcessData() * @param int $signal A valid POSIX signal (see https://php.net/pcntl.constants) * @param bool $throwException Whether to throw exception in case signal failed * - * @return bool - * * @throws LogicException In case the process is not running * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed * @throws RuntimeException In case of failure diff --git a/ProcessUtils.php b/ProcessUtils.php index 6cc7a610..6fedd34d 100644 --- a/ProcessUtils.php +++ b/ProcessUtils.php @@ -35,11 +35,9 @@ private function __construct() * @param string $caller The name of method call that validates the input * @param mixed $input The input to validate * - * @return mixed - * * @throws InvalidArgumentException In case the input is not valid */ - public static function validateInput(string $caller, $input) + public static function validateInput(string $caller, mixed $input): mixed { if (null !== $input) { if (\is_resource($input)) { diff --git a/composer.json b/composer.json index 1669eba5..9f1aa8cf 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,7 @@ } ], "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.0.2" }, "autoload": { "psr-4": { "Symfony\\Component\\Process\\": "" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c32f2510..13bd3f83 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ - - + + ./ - - ./Tests - ./vendor - - - + + + ./Tests + ./vendor + +