fix:更新已知bug,优化代码

This commit is contained in:
Ying
2022-11-28 19:11:12 +08:00
parent f6aee95cfc
commit 9445b206a2
1378 changed files with 53759 additions and 20789 deletions

View File

@@ -46,11 +46,11 @@ class InputOption
*/
public const VALUE_NEGATABLE = 16;
private $name;
private $shortcut;
private $mode;
private $default;
private $description;
private string $name;
private string|array|null $shortcut;
private int $mode;
private string|int|bool|array|null|float $default;
private string $description;
/**
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
@@ -59,7 +59,7 @@ class InputOption
*
* @throws InvalidArgumentException If option mode is invalid or incompatible
*/
public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
public function __construct(string $name, string|array $shortcut = null, int $mode = null, string $description = '', string|bool|int|float|array $default = null)
{
if (str_starts_with($name, '--')) {
$name = substr($name, 2);
@@ -109,20 +109,16 @@ class InputOption
/**
* Returns the option shortcut.
*
* @return string|null
*/
public function getShortcut()
public function getShortcut(): ?string
{
return $this->shortcut;
}
/**
* Returns the option name.
*
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}
@@ -132,7 +128,7 @@ class InputOption
*
* @return bool true if value mode is not self::VALUE_NONE, false otherwise
*/
public function acceptValue()
public function acceptValue(): bool
{
return $this->isValueRequired() || $this->isValueOptional();
}
@@ -142,7 +138,7 @@ class InputOption
*
* @return bool true if value mode is self::VALUE_REQUIRED, false otherwise
*/
public function isValueRequired()
public function isValueRequired(): bool
{
return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
}
@@ -152,7 +148,7 @@ class InputOption
*
* @return bool true if value mode is self::VALUE_OPTIONAL, false otherwise
*/
public function isValueOptional()
public function isValueOptional(): bool
{
return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
}
@@ -162,7 +158,7 @@ class InputOption
*
* @return bool true if mode is self::VALUE_IS_ARRAY, false otherwise
*/
public function isArray()
public function isArray(): bool
{
return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
}
@@ -172,10 +168,7 @@ class InputOption
return self::VALUE_NEGATABLE === (self::VALUE_NEGATABLE & $this->mode);
}
/**
* @param string|bool|int|float|array|null $default
*/
public function setDefault($default = null)
public function setDefault(string|bool|int|float|array $default = null)
{
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
@@ -194,30 +187,24 @@ class InputOption
/**
* Returns the default value.
*
* @return string|bool|int|float|array|null
*/
public function getDefault()
public function getDefault(): string|bool|int|float|array|null
{
return $this->default;
}
/**
* Returns the description text.
*
* @return string
*/
public function getDescription()
public function getDescription(): string
{
return $this->description;
}
/**
* Checks whether the given option equals this one.
*
* @return bool
*/
public function equals(self $option)
public function equals(self $option): bool
{
return $option->getName() === $this->getName()
&& $option->getShortcut() === $this->getShortcut()