Skip to content

Commit 57834cb

Browse files
lubianaadhocore
authored andcommitted
make parameters with null default value explicitly nullable
1 parent 8d776d0 commit 57834cb

10 files changed

+30
-30
lines changed

src/Application.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Application
6363
/** @var callable The callable to catch exception, receives exception & exit code, may rethrow exception or may exit program */
6464
protected $onException = null;
6565

66-
public function __construct(protected string $name, protected string $version = '0.0.1', callable $onExit = null)
66+
public function __construct(protected string $name, protected string $version = '0.0.1', ?callable $onExit = null)
6767
{
6868
$this->onExit = $onExit ?? static fn (int $exitCode = 0) => exit($exitCode);
6969

@@ -115,7 +115,7 @@ public function argv(): array
115115
*
116116
* @return string|self
117117
*/
118-
public function logo(string $logo = null)
118+
public function logo(?string $logo = null)
119119
{
120120
if (func_num_args() === 0) {
121121
return $this->logo;
@@ -247,7 +247,7 @@ public function commandFor(array $argv): Command
247247
*
248248
* @return Interactor|self
249249
*/
250-
public function io(Interactor $io = null)
250+
public function io(?Interactor $io = null)
251251
{
252252
if ($io || !$this->io) {
253253
$this->io = $io ?? new Interactor;

src/Helper/Normalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function normalizeArgs(array $args): array
5757
/**
5858
* Normalizes value as per context and runs thorugh filter if possible.
5959
*/
60-
public function normalizeValue(Parameter $parameter, string $value = null): mixed
60+
public function normalizeValue(Parameter $parameter, ?string $value = null): mixed
6161
{
6262
if ($parameter instanceof Option && $parameter->bool()) {
6363
return !$parameter->default();

src/Helper/OutputHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class OutputHelper
6363
/** @var int Max width of command name */
6464
protected int $maxCmdName = 0;
6565

66-
public function __construct(Writer $writer = null)
66+
public function __construct(?Writer $writer = null)
6767
{
6868
$this->writer = $writer ?? new Writer;
6969
}

src/Helper/Shell.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ protected function checkTimeout(): void
188188
// @codeCoverageIgnoreEnd
189189

190190
public function setOptions(
191-
string $cwd = null,
191+
?string $cwd = null,
192192
?array $env = null,
193-
float $timeout = null,
193+
?float $timeout = null,
194194
array $otherOptions = []
195195
): self {
196196
$this->cwd = $cwd;

src/IO/Interactor.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class Interactor
188188
* @param string|null $input Input stream path.
189189
* @param string|null $output Output steam path.
190190
*/
191-
public function __construct(string $input = null, string $output = null)
191+
public function __construct(?string $input = null, ?string $output = null)
192192
{
193193
$this->reader = new Reader($input);
194194
$this->writer = new Writer($output);
@@ -294,7 +294,7 @@ public function choices(string $text, array $choices, $default = null, bool $cas
294294
*
295295
* @return mixed
296296
*/
297-
public function prompt(string $text, $default = null, callable $fn = null, int $retry = 3): mixed
297+
public function prompt(string $text, $default = null, ?callable $fn = null, int $retry = 3): mixed
298298
{
299299
$error = 'Invalid value. Please try again!';
300300
$hidden = func_get_args()[4] ?? false;
@@ -328,7 +328,7 @@ public function prompt(string $text, $default = null, callable $fn = null, int $
328328
*
329329
* @return mixed
330330
*/
331-
public function promptHidden(string $text, callable $fn = null, int $retry = 3): mixed
331+
public function promptHidden(string $text, ?callable $fn = null, int $retry = 3): mixed
332332
{
333333
return $this->prompt($text, null, $fn, $retry, true);
334334
}

src/Input/Command.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function app(): ?App
145145
/**
146146
* Bind command to the app.
147147
*/
148-
public function bind(App $app = null): self
148+
public function bind(?App $app = null): self
149149
{
150150
$this->_app = $app;
151151

@@ -189,7 +189,7 @@ public function argument(string $raw, string $desc = '', $default = null): self
189189
/**
190190
* Registers new option.
191191
*/
192-
public function option(string $raw, string $desc = '', callable $filter = null, $default = null): self
192+
public function option(string $raw, string $desc = '', ?callable $filter = null, $default = null): self
193193
{
194194
$option = new Option($raw, $desc, $default, $filter);
195195

@@ -217,7 +217,7 @@ public function userOptions(): array
217217
*
218218
* @return string|self
219219
*/
220-
public function usage(string $usage = null)
220+
public function usage(?string $usage = null)
221221
{
222222
if (func_num_args() === 0) {
223223
return $this->_usage;
@@ -235,7 +235,7 @@ public function usage(string $usage = null)
235235
*
236236
* @return string|self
237237
*/
238-
public function alias(string $alias = null)
238+
public function alias(?string $alias = null)
239239
{
240240
if (func_num_args() === 0) {
241241
return $this->_alias;
@@ -249,7 +249,7 @@ public function alias(string $alias = null)
249249
/**
250250
* Sets event handler for last (or given) option.
251251
*/
252-
public function on(callable $fn, string $option = null): self
252+
public function on(callable $fn, ?string $option = null): self
253253
{
254254
$names = array_keys($this->allOptions());
255255

@@ -271,7 +271,7 @@ public function onExit(callable $fn): self
271271
/**
272272
* {@inheritdoc}
273273
*/
274-
protected function handleUnknown(string $arg, string $value = null): mixed
274+
protected function handleUnknown(string $arg, ?string $value = null): mixed
275275
{
276276
if ($this->_allowUnknown) {
277277
return $this->set($this->toCamelCase($arg), $value);
@@ -338,7 +338,7 @@ public function emit(string $event, $value = null): mixed
338338
/**
339339
* Tap return given object or if that is null then app instance. This aids for chaining.
340340
*/
341-
public function tap(object $object = null)
341+
public function tap(?object $object = null)
342342
{
343343
return $object ?? $this->_app;
344344
}
@@ -358,7 +358,7 @@ public function interact(Interactor $io): void
358358
*
359359
* @return callable|self If $action provided then self, otherwise the preset action.
360360
*/
361-
public function action(callable $action = null)
361+
public function action(?callable $action = null)
362362
{
363363
if (func_num_args() === 0) {
364364
return $this->_action;
@@ -388,7 +388,7 @@ protected function io(): Interactor
388388
/**
389389
* Get ProgressBar instance.
390390
*/
391-
protected function progress(int $total = null): ProgressBar
391+
protected function progress(?int $total = null): ProgressBar
392392
{
393393
return new ProgressBar($total, $this->writer());
394394
}

src/Input/Parser.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected function parseArgs(string $arg)
118118
*
119119
* @return bool Whether to eat next arg.
120120
*/
121-
protected function parseOptions(string $arg, string $nextArg = null): bool
121+
protected function parseOptions(string $arg, ?string $nextArg = null): bool
122122
{
123123
$value = substr($nextArg ?? '', 0, 1) === '-' ? null : $nextArg;
124124

@@ -155,7 +155,7 @@ protected function optionFor(string $arg): ?Option
155155
*
156156
* @return mixed If true it will indicate that value has been eaten.
157157
*/
158-
abstract protected function handleUnknown(string $arg, string $value = null): mixed;
158+
abstract protected function handleUnknown(string $arg, ?string $value = null): mixed;
159159

160160
/**
161161
* Emit the event with value.
@@ -175,7 +175,7 @@ abstract protected function emit(string $event, $value = null): mixed;
175175
*
176176
* @return bool Indicating whether it has eaten adjoining arg to its right.
177177
*/
178-
protected function setValue(Parameter $parameter, string $value = null): bool
178+
protected function setValue(Parameter $parameter, ?string $value = null): bool
179179
{
180180
$name = $parameter->attributeName();
181181
$value = $this->_normalizer->normalizeValue($parameter, $value);

src/Input/Reader.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Reader
4242
*
4343
* @param string|null $path Read path. Defaults to STDIN.
4444
*/
45-
public function __construct(string $path = null)
45+
public function __construct(?string $path = null)
4646
{
4747
$this->stream = $path ? fopen($path, 'r') : STDIN;
4848
}
@@ -55,7 +55,7 @@ public function __construct(string $path = null)
5555
*
5656
* @return mixed
5757
*/
58-
public function read($default = null, callable $fn = null): mixed
58+
public function read($default = null, ?callable $fn = null): mixed
5959
{
6060
$in = rtrim(fgets($this->stream), "\r\n");
6161

@@ -75,7 +75,7 @@ public function read($default = null, callable $fn = null): mixed
7575
*
7676
* @return string
7777
*/
78-
public function readAll(callable $fn = null): string
78+
public function readAll(?callable $fn = null): string
7979
{
8080
$in = stream_get_contents($this->stream);
8181

@@ -91,7 +91,7 @@ public function readAll(callable $fn = null): string
9191
*
9292
* @return string
9393
*/
94-
public function readPiped(callable $fn = null): string
94+
public function readPiped(?callable $fn = null): string
9595
{
9696
$stdin = '';
9797
$read = [$this->stream];
@@ -118,7 +118,7 @@ public function readPiped(callable $fn = null): string
118118
*
119119
* @return mixed
120120
*/
121-
public function readHidden($default = null, callable $fn = null): mixed
121+
public function readHidden($default = null, ?callable $fn = null): mixed
122122
{
123123
// @codeCoverageIgnoreStart
124124
if ('\\' === DIRECTORY_SEPARATOR) {
@@ -144,7 +144,7 @@ public function readHidden($default = null, callable $fn = null): mixed
144144
*
145145
* @return mixed
146146
*/
147-
protected function readHiddenWinOS($default = null, callable $fn = null): mixed
147+
protected function readHiddenWinOS($default = null, ?callable $fn = null): mixed
148148
{
149149
$cmd = 'powershell -Command ' . implode('; ', array_filter([
150150
'$pword = Read-Host -AsSecureString',

src/Output/ProgressBar.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function forceRedraw(bool $force = true): self
202202
* @param iterable $items Array or any other iterable object
203203
* @param callable $callback A handler to run on each item
204204
*/
205-
public function each($items, callable $callback = null)
205+
public function each($items, ?callable $callback = null)
206206
{
207207
if ($items instanceof \Traversable) {
208208
$items = iterator_to_array($items);

src/Output/Writer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class Writer
188188

189189
protected Terminal $terminal;
190190

191-
public function __construct(string $path = null, Color $colorizer = null)
191+
public function __construct(?string $path = null, ?Color $colorizer = null)
192192
{
193193
if ($path) {
194194
$path = fopen($path, 'w');

0 commit comments

Comments
 (0)