Skip to content

Commit 8f38ed0

Browse files
Add types to private and internal properties
1 parent 1132f6e commit 8f38ed0

10 files changed

+46
-51
lines changed

Exception/ProcessFailedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class ProcessFailedException extends RuntimeException
2222
{
23-
private $process;
23+
private Process $process;
2424

2525
public function __construct(Process $process)
2626
{

Exception/ProcessSignaledException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
final class ProcessSignaledException extends RuntimeException
2222
{
23-
private $process;
23+
private Process $process;
2424

2525
public function __construct(Process $process)
2626
{

Exception/ProcessTimedOutException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class ProcessTimedOutException extends RuntimeException
2323
public const TYPE_GENERAL = 1;
2424
public const TYPE_IDLE = 2;
2525

26-
private $process;
27-
private $timeoutType;
26+
private Process $process;
27+
private int $timeoutType;
2828

2929
public function __construct(Process $process, int $timeoutType)
3030
{

ExecutableFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class ExecutableFinder
2121
{
22-
private $suffixes = ['.exe', '.bat', '.cmd', '.com'];
22+
private array $suffixes = ['.exe', '.bat', '.cmd', '.com'];
2323

2424
/**
2525
* Replaces default suffixes of executable.

InputStream.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
*/
2323
class InputStream implements \IteratorAggregate
2424
{
25-
/** @var callable|null */
26-
private $onEmpty;
27-
private $input = [];
28-
private $open = true;
25+
private ?\Closure $onEmpty = null;
26+
private array $input = [];
27+
private bool $open = true;
2928

3029
/**
3130
* Sets a callback that is called when the write buffer becomes empty.
@@ -34,7 +33,7 @@ class InputStream implements \IteratorAggregate
3433
*/
3534
public function onEmpty(callable $onEmpty = null)
3635
{
37-
$this->onEmpty = $onEmpty;
36+
$this->onEmpty = null !== $onEmpty ? $onEmpty(...) : null;
3837
}
3938

4039
/**

PhpExecutableFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class PhpExecutableFinder
2121
{
22-
private $executableFinder;
22+
private ExecutableFinder $executableFinder;
2323

2424
public function __construct()
2525
{

Pipes/AbstractPipes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ abstract class AbstractPipes implements PipesInterface
2222
{
2323
public array $pipes = [];
2424

25-
private $inputBuffer = '';
25+
private string $inputBuffer = '';
2626
private $input;
27-
private $blocked = true;
28-
private $lastError;
27+
private bool $blocked = true;
28+
private ?string $lastError = null;
2929

3030
/**
3131
* @param resource|string|int|float|bool|\Iterator|null $input

Pipes/UnixPipes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
*/
2323
class UnixPipes extends AbstractPipes
2424
{
25-
private $ttyMode;
26-
private $ptyMode;
27-
private $haveReadSupport;
25+
private ?bool $ttyMode;
26+
private bool $ptyMode;
27+
private bool $haveReadSupport;
2828

2929
public function __construct(?bool $ttyMode, bool $ptyMode, mixed $input, bool $haveReadSupport)
3030
{

Pipes/WindowsPipes.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
*/
2727
class WindowsPipes extends AbstractPipes
2828
{
29-
private $files = [];
30-
private $fileHandles = [];
31-
private $lockHandles = [];
32-
private $readBytes = [
29+
private array $files = [];
30+
private array $fileHandles = [];
31+
private array $lockHandles = [];
32+
private array $readBytes = [
3333
Process::STDOUT => 0,
3434
Process::STDERR => 0,
3535
];
36-
private $haveReadSupport;
36+
private bool $haveReadSupport;
3737

3838
public function __construct(mixed $input, bool $haveReadSupport)
3939
{

Process.php

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Process\Exception\ProcessSignaledException;
1818
use Symfony\Component\Process\Exception\ProcessTimedOutException;
1919
use Symfony\Component\Process\Exception\RuntimeException;
20-
use Symfony\Component\Process\Pipes\PipesInterface;
2120
use Symfony\Component\Process\Pipes\UnixPipes;
2221
use Symfony\Component\Process\Pipes\WindowsPipes;
2322

@@ -51,37 +50,35 @@ class Process implements \IteratorAggregate
5150
public const ITER_SKIP_OUT = 4; // Use this flag to skip STDOUT while iterating
5251
public const ITER_SKIP_ERR = 8; // Use this flag to skip STDERR while iterating
5352

54-
private $callback;
55-
private $hasCallback = false;
56-
private $commandline;
57-
private $cwd;
58-
private $env = [];
53+
private ?\Closure $callback = null;
54+
private array|string $commandline;
55+
private ?string $cwd;
56+
private array $env = [];
5957
private $input;
60-
private $starttime;
61-
private $lastOutputTime;
62-
private $timeout;
63-
private $idleTimeout;
64-
private $exitcode;
65-
private $fallbackStatus = [];
66-
private $processInformation;
67-
private $outputDisabled = false;
58+
private ?float $starttime = null;
59+
private ?float $lastOutputTime = null;
60+
private ?float $timeout = null;
61+
private ?float $idleTimeout = null;
62+
private ?int $exitcode = null;
63+
private array $fallbackStatus = [];
64+
private array $processInformation;
65+
private bool $outputDisabled = false;
6866
private $stdout;
6967
private $stderr;
7068
private $process;
71-
private $status = self::STATUS_READY;
72-
private $incrementalOutputOffset = 0;
73-
private $incrementalErrorOutputOffset = 0;
74-
private $tty = false;
75-
private $pty;
76-
private $options = ['suppress_errors' => true, 'bypass_shell' => true];
69+
private string $status = self::STATUS_READY;
70+
private int $incrementalOutputOffset = 0;
71+
private int $incrementalErrorOutputOffset = 0;
72+
private bool $tty = false;
73+
private bool $pty;
74+
private array $options = ['suppress_errors' => true, 'bypass_shell' => true];
7775

78-
private $useFileHandles = false;
79-
/** @var PipesInterface */
80-
private $processPipes;
76+
private bool $useFileHandles;
77+
private WindowsPipes|UnixPipes $processPipes;
8178

82-
private $latestSignal;
79+
private ?int $latestSignal = null;
8380

84-
private static $sigchild;
81+
private static ?bool $sigchild = null;
8582

8683
/**
8784
* Exit codes translation table.
@@ -303,7 +300,6 @@ public function start(callable $callback = null, array $env = [])
303300
$this->resetProcessData();
304301
$this->starttime = $this->lastOutputTime = microtime(true);
305302
$this->callback = $this->buildCallback($callback);
306-
$this->hasCallback = null !== $callback;
307303
$descriptors = $this->getDescriptors();
308304

309305
if ($this->env) {
@@ -1245,9 +1241,9 @@ private function getDescriptors(): array
12451241
$this->input->rewind();
12461242
}
12471243
if ('\\' === \DIRECTORY_SEPARATOR) {
1248-
$this->processPipes = new WindowsPipes($this->input, !$this->outputDisabled || $this->hasCallback);
1244+
$this->processPipes = new WindowsPipes($this->input, !$this->outputDisabled || $this->callback);
12491245
} else {
1250-
$this->processPipes = new UnixPipes($this->isTty(), $this->isPty(), $this->input, !$this->outputDisabled || $this->hasCallback);
1246+
$this->processPipes = new UnixPipes($this->isTty(), $this->isPty(), $this->input, !$this->outputDisabled || $this->callback);
12511247
}
12521248

12531249
return $this->processPipes->getDescriptors();
@@ -1424,7 +1420,7 @@ private function resetProcessData(): void
14241420
$this->callback = null;
14251421
$this->exitcode = null;
14261422
$this->fallbackStatus = [];
1427-
$this->processInformation = null;
1423+
$this->processInformation = [];
14281424
$this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+');
14291425
$this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+');
14301426
$this->process = null;

0 commit comments

Comments
 (0)