Skip to content

Commit 258d1a6

Browse files
committed
fix
1 parent 1f472c7 commit 258d1a6

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

phpstan-stubs/InputOption.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\Console\Input;
6+
7+
class InputOption
8+
{
9+
/**
10+
* Returns true if the option can take multiple values.
11+
*
12+
* @return bool true if mode is self::VALUE_IS_ARRAY, false otherwise
13+
*/
14+
public function isArray(): bool;
15+
}

src/Input/InputOptionsSerializer.php

+20-24
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private function __construct()
4646
public static function serialize(
4747
InputDefinition $commandDefinition,
4848
InputInterface $input,
49-
array $excludedOptionNames
49+
array $excludedOptionNames,
5050
): array {
5151
$filteredOptions = array_diff_key(
5252
RawInput::getRawOptions($input),
@@ -78,36 +78,32 @@ private static function serializeOption(
7878
string $name,
7979
array|bool|float|int|string|null $value,
8080
): string|array {
81-
if ($option->isNegatable()) {
82-
return sprintf(
83-
'--%s%s',
84-
$value ? '' : 'no-',
85-
$name,
86-
);
87-
}
88-
89-
if (!$option->acceptValue()) {
90-
return sprintf(
91-
'--%s',
92-
$name,
93-
);
94-
}
95-
96-
if ($option->isArray()) {
97-
/** @var array<string|bool|int|float|null> $value */
98-
return array_map(
81+
return match (true) {
82+
$option->isNegatable() => sprintf('--%s%s', $value ? '' : 'no-', $name),
83+
!$option->acceptValue() => sprintf('--%s', $name),
84+
self::isArray($option, $value) => array_map(
9985
static fn ($item) => self::serializeOptionWithValue($name, $item),
10086
$value,
101-
);
102-
}
87+
),
88+
default => self::serializeOptionWithValue($name, $value),
89+
};
90+
}
10391

104-
/** @var string|bool|int|float|null $value */
105-
return self::serializeOptionWithValue($name, $value);
92+
/**
93+
* @param string|bool|int|float|null|array<string|bool|int|float|null> $value
94+
*
95+
* @phpstan-assert-if-true array<string|bool|int|float|null> $value
96+
*/
97+
private static function isArray(
98+
InputOption $option,
99+
array|bool|float|int|string|null $value,
100+
): bool {
101+
return $option->isArray();
106102
}
107103

108104
private static function serializeOptionWithValue(
109105
string $name,
110-
bool|float|int|string|null $value
106+
bool|float|int|string|null $value,
111107
): string {
112108
return sprintf(
113109
'--%s=%s',

0 commit comments

Comments
 (0)