diff --git a/src/Application.php b/src/Application.php index 5fc89f7..4e15610 100644 --- a/src/Application.php +++ b/src/Application.php @@ -63,7 +63,7 @@ class Application /** @var callable The callable to catch exception, receives exception & exit code, may rethrow exception or may exit program */ protected $onException = null; - public function __construct(protected string $name, protected string $version = '0.0.1', callable $onExit = null) + public function __construct(protected string $name, protected string $version = '0.0.1', ?callable $onExit = null) { $this->onExit = $onExit ?? static fn (int $exitCode = 0) => exit($exitCode); @@ -115,7 +115,7 @@ public function argv(): array * * @return string|self */ - public function logo(string $logo = null) + public function logo(?string $logo = null) { if (func_num_args() === 0) { return $this->logo; @@ -247,7 +247,7 @@ public function commandFor(array $argv): Command * * @return Interactor|self */ - public function io(Interactor $io = null) + public function io(?Interactor $io = null) { if ($io || !$this->io) { $this->io = $io ?? new Interactor; diff --git a/src/Helper/Normalizer.php b/src/Helper/Normalizer.php index 4c71c48..470114f 100644 --- a/src/Helper/Normalizer.php +++ b/src/Helper/Normalizer.php @@ -57,7 +57,7 @@ public function normalizeArgs(array $args): array /** * Normalizes value as per context and runs thorugh filter if possible. */ - public function normalizeValue(Parameter $parameter, string $value = null): mixed + public function normalizeValue(Parameter $parameter, ?string $value = null): mixed { if ($parameter instanceof Option && $parameter->bool()) { return !$parameter->default(); diff --git a/src/Helper/OutputHelper.php b/src/Helper/OutputHelper.php index 8685509..7cf9c5c 100644 --- a/src/Helper/OutputHelper.php +++ b/src/Helper/OutputHelper.php @@ -63,7 +63,7 @@ class OutputHelper /** @var int Max width of command name */ protected int $maxCmdName = 0; - public function __construct(Writer $writer = null) + public function __construct(?Writer $writer = null) { $this->writer = $writer ?? new Writer; } diff --git a/src/Helper/Shell.php b/src/Helper/Shell.php index cb83d4c..3666d5d 100644 --- a/src/Helper/Shell.php +++ b/src/Helper/Shell.php @@ -188,9 +188,9 @@ protected function checkTimeout(): void // @codeCoverageIgnoreEnd public function setOptions( - string $cwd = null, + ?string $cwd = null, ?array $env = null, - float $timeout = null, + ?float $timeout = null, array $otherOptions = [] ): self { $this->cwd = $cwd; diff --git a/src/IO/Interactor.php b/src/IO/Interactor.php index 0971b1b..37c5a78 100644 --- a/src/IO/Interactor.php +++ b/src/IO/Interactor.php @@ -188,7 +188,7 @@ class Interactor * @param string|null $input Input stream path. * @param string|null $output Output steam path. */ - public function __construct(string $input = null, string $output = null) + public function __construct(?string $input = null, ?string $output = null) { $this->reader = new Reader($input); $this->writer = new Writer($output); @@ -294,7 +294,7 @@ public function choices(string $text, array $choices, $default = null, bool $cas * * @return mixed */ - public function prompt(string $text, $default = null, callable $fn = null, int $retry = 3): mixed + public function prompt(string $text, $default = null, ?callable $fn = null, int $retry = 3): mixed { $error = 'Invalid value. Please try again!'; $hidden = func_get_args()[4] ?? false; @@ -328,7 +328,7 @@ public function prompt(string $text, $default = null, callable $fn = null, int $ * * @return mixed */ - public function promptHidden(string $text, callable $fn = null, int $retry = 3): mixed + public function promptHidden(string $text, ?callable $fn = null, int $retry = 3): mixed { return $this->prompt($text, null, $fn, $retry, true); } diff --git a/src/Input/Command.php b/src/Input/Command.php index 723ef76..5b999ee 100644 --- a/src/Input/Command.php +++ b/src/Input/Command.php @@ -145,7 +145,7 @@ public function app(): ?App /** * Bind command to the app. */ - public function bind(App $app = null): self + public function bind(?App $app = null): self { $this->_app = $app; @@ -189,7 +189,7 @@ public function argument(string $raw, string $desc = '', $default = null): self /** * Registers new option. */ - public function option(string $raw, string $desc = '', callable $filter = null, $default = null): self + public function option(string $raw, string $desc = '', ?callable $filter = null, $default = null): self { $option = new Option($raw, $desc, $default, $filter); @@ -217,7 +217,7 @@ public function userOptions(): array * * @return string|self */ - public function usage(string $usage = null) + public function usage(?string $usage = null) { if (func_num_args() === 0) { return $this->_usage; @@ -235,7 +235,7 @@ public function usage(string $usage = null) * * @return string|self */ - public function alias(string $alias = null) + public function alias(?string $alias = null) { if (func_num_args() === 0) { return $this->_alias; @@ -249,7 +249,7 @@ public function alias(string $alias = null) /** * Sets event handler for last (or given) option. */ - public function on(callable $fn, string $option = null): self + public function on(callable $fn, ?string $option = null): self { $names = array_keys($this->allOptions()); @@ -271,7 +271,7 @@ public function onExit(callable $fn): self /** * {@inheritdoc} */ - protected function handleUnknown(string $arg, string $value = null): mixed + protected function handleUnknown(string $arg, ?string $value = null): mixed { if ($this->_allowUnknown) { return $this->set($this->toCamelCase($arg), $value); @@ -338,7 +338,7 @@ public function emit(string $event, $value = null): mixed /** * Tap return given object or if that is null then app instance. This aids for chaining. */ - public function tap(object $object = null) + public function tap(?object $object = null) { return $object ?? $this->_app; } @@ -358,7 +358,7 @@ public function interact(Interactor $io): void * * @return callable|self If $action provided then self, otherwise the preset action. */ - public function action(callable $action = null) + public function action(?callable $action = null) { if (func_num_args() === 0) { return $this->_action; @@ -388,7 +388,7 @@ protected function io(): Interactor /** * Get ProgressBar instance. */ - protected function progress(int $total = null): ProgressBar + protected function progress(?int $total = null): ProgressBar { return new ProgressBar($total, $this->writer()); } diff --git a/src/Input/Parser.php b/src/Input/Parser.php index 69a7876..42977ca 100644 --- a/src/Input/Parser.php +++ b/src/Input/Parser.php @@ -118,7 +118,7 @@ protected function parseArgs(string $arg) * * @return bool Whether to eat next arg. */ - protected function parseOptions(string $arg, string $nextArg = null): bool + protected function parseOptions(string $arg, ?string $nextArg = null): bool { $value = substr($nextArg ?? '', 0, 1) === '-' ? null : $nextArg; @@ -155,7 +155,7 @@ protected function optionFor(string $arg): ?Option * * @return mixed If true it will indicate that value has been eaten. */ - abstract protected function handleUnknown(string $arg, string $value = null): mixed; + abstract protected function handleUnknown(string $arg, ?string $value = null): mixed; /** * Emit the event with value. @@ -175,7 +175,7 @@ abstract protected function emit(string $event, $value = null): mixed; * * @return bool Indicating whether it has eaten adjoining arg to its right. */ - protected function setValue(Parameter $parameter, string $value = null): bool + protected function setValue(Parameter $parameter, ?string $value = null): bool { $name = $parameter->attributeName(); $value = $this->_normalizer->normalizeValue($parameter, $value); diff --git a/src/Input/Reader.php b/src/Input/Reader.php index 1e2c008..9e0f907 100644 --- a/src/Input/Reader.php +++ b/src/Input/Reader.php @@ -42,7 +42,7 @@ class Reader * * @param string|null $path Read path. Defaults to STDIN. */ - public function __construct(string $path = null) + public function __construct(?string $path = null) { $this->stream = $path ? fopen($path, 'r') : STDIN; } @@ -55,7 +55,7 @@ public function __construct(string $path = null) * * @return mixed */ - public function read($default = null, callable $fn = null): mixed + public function read($default = null, ?callable $fn = null): mixed { $in = rtrim(fgets($this->stream), "\r\n"); @@ -75,7 +75,7 @@ public function read($default = null, callable $fn = null): mixed * * @return string */ - public function readAll(callable $fn = null): string + public function readAll(?callable $fn = null): string { $in = stream_get_contents($this->stream); @@ -91,7 +91,7 @@ public function readAll(callable $fn = null): string * * @return string */ - public function readPiped(callable $fn = null): string + public function readPiped(?callable $fn = null): string { $stdin = ''; $read = [$this->stream]; @@ -118,7 +118,7 @@ public function readPiped(callable $fn = null): string * * @return mixed */ - public function readHidden($default = null, callable $fn = null): mixed + public function readHidden($default = null, ?callable $fn = null): mixed { // @codeCoverageIgnoreStart if ('\\' === DIRECTORY_SEPARATOR) { @@ -144,7 +144,7 @@ public function readHidden($default = null, callable $fn = null): mixed * * @return mixed */ - protected function readHiddenWinOS($default = null, callable $fn = null): mixed + protected function readHiddenWinOS($default = null, ?callable $fn = null): mixed { $cmd = 'powershell -Command ' . implode('; ', array_filter([ '$pword = Read-Host -AsSecureString', diff --git a/src/Output/ProgressBar.php b/src/Output/ProgressBar.php index ff3e2d0..dcb4e27 100644 --- a/src/Output/ProgressBar.php +++ b/src/Output/ProgressBar.php @@ -202,7 +202,7 @@ public function forceRedraw(bool $force = true): self * @param iterable $items Array or any other iterable object * @param callable $callback A handler to run on each item */ - public function each($items, callable $callback = null) + public function each($items, ?callable $callback = null) { if ($items instanceof \Traversable) { $items = iterator_to_array($items); diff --git a/src/Output/Writer.php b/src/Output/Writer.php index aeda5d5..35bf90f 100644 --- a/src/Output/Writer.php +++ b/src/Output/Writer.php @@ -188,7 +188,7 @@ class Writer protected Terminal $terminal; - public function __construct(string $path = null, Color $colorizer = null) + public function __construct(?string $path = null, ?Color $colorizer = null) { if ($path) { $path = fopen($path, 'w');