Skip to content

Commit

Permalink
make parameters with null default value explicitly nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
lubiana authored and adhocore committed Sep 5, 2024
1 parent 8d776d0 commit 57834cb
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/Normalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/OutputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Helper/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/IO/Interactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Input/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
6 changes: 3 additions & 3 deletions src/Input/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/Input/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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");

Expand All @@ -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);

Expand All @@ -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];
Expand All @@ -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) {
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/Output/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Output/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 57834cb

Please sign in to comment.