package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -20,17 +20,17 @@ use Symfony\Component\Console\Exception\InvalidArgumentException;
*/
class ChoiceQuestion extends Question
{
private $choices;
private $multiselect = false;
private $prompt = ' > ';
private $errorMessage = 'Value "%s" is invalid';
private array $choices;
private bool $multiselect = false;
private string $prompt = ' > ';
private string $errorMessage = 'Value "%s" is invalid';
/**
* @param string $question The question to ask to the user
* @param array $choices The list of available choices
* @param mixed $default The default answer to return
*/
public function __construct(string $question, array $choices, $default = null)
public function __construct(string $question, array $choices, mixed $default = null)
{
if (!$choices) {
throw new \LogicException('Choice question must have at least 1 choice available.');
@@ -45,10 +45,8 @@ class ChoiceQuestion extends Question
/**
* Returns available choices.
*
* @return array
*/
public function getChoices()
public function getChoices(): array
{
return $this->choices;
}
@@ -60,7 +58,7 @@ class ChoiceQuestion extends Question
*
* @return $this
*/
public function setMultiselect(bool $multiselect)
public function setMultiselect(bool $multiselect): static
{
$this->multiselect = $multiselect;
$this->setValidator($this->getDefaultValidator());
@@ -70,20 +68,16 @@ class ChoiceQuestion extends Question
/**
* Returns whether the choices are multiselect.
*
* @return bool
*/
public function isMultiselect()
public function isMultiselect(): bool
{
return $this->multiselect;
}
/**
* Gets the prompt for choices.
*
* @return string
*/
public function getPrompt()
public function getPrompt(): string
{
return $this->prompt;
}
@@ -93,7 +87,7 @@ class ChoiceQuestion extends Question
*
* @return $this
*/
public function setPrompt(string $prompt)
public function setPrompt(string $prompt): static
{
$this->prompt = $prompt;
@@ -107,7 +101,7 @@ class ChoiceQuestion extends Question
*
* @return $this
*/
public function setErrorMessage(string $errorMessage)
public function setErrorMessage(string $errorMessage): static
{
$this->errorMessage = $errorMessage;
$this->setValidator($this->getDefaultValidator());

View File

@@ -18,7 +18,7 @@ namespace Symfony\Component\Console\Question;
*/
class ConfirmationQuestion extends Question
{
private $trueAnswerRegex;
private string $trueAnswerRegex;
/**
* @param string $question The question to ask to the user

View File

@@ -21,22 +21,22 @@ use Symfony\Component\Console\Exception\LogicException;
*/
class Question
{
private $question;
private $attempts;
private $hidden = false;
private $hiddenFallback = true;
private $autocompleterCallback;
private $validator;
private $default;
private $normalizer;
private $trimmable = true;
private $multiline = false;
private string $question;
private ?int $attempts = null;
private bool $hidden = false;
private bool $hiddenFallback = true;
private ?\Closure $autocompleterCallback = null;
private ?\Closure $validator = null;
private string|int|bool|null|float $default;
private ?\Closure $normalizer = null;
private bool $trimmable = true;
private bool $multiline = false;
/**
* @param string $question The question to ask to the user
* @param string|bool|int|float|null $default The default answer to return if the user enters nothing
*/
public function __construct(string $question, $default = null)
public function __construct(string $question, string|bool|int|float $default = null)
{
$this->question = $question;
$this->default = $default;
@@ -44,20 +44,16 @@ class Question
/**
* Returns the question.
*
* @return string
*/
public function getQuestion()
public function getQuestion(): string
{
return $this->question;
}
/**
* Returns the default answer.
*
* @return string|bool|int|float|null
*/
public function getDefault()
public function getDefault(): string|bool|int|float|null
{
return $this->default;
}
@@ -75,7 +71,7 @@ class Question
*
* @return $this
*/
public function setMultiline(bool $multiline): self
public function setMultiline(bool $multiline): static
{
$this->multiline = $multiline;
@@ -84,10 +80,8 @@ class Question
/**
* Returns whether the user response must be hidden.
*
* @return bool
*/
public function isHidden()
public function isHidden(): bool
{
return $this->hidden;
}
@@ -99,7 +93,7 @@ class Question
*
* @throws LogicException In case the autocompleter is also used
*/
public function setHidden(bool $hidden)
public function setHidden(bool $hidden): static
{
if ($this->autocompleterCallback) {
throw new LogicException('A hidden question cannot use the autocompleter.');
@@ -112,10 +106,8 @@ class Question
/**
* In case the response cannot be hidden, whether to fallback on non-hidden question or not.
*
* @return bool
*/
public function isHiddenFallback()
public function isHiddenFallback(): bool
{
return $this->hiddenFallback;
}
@@ -125,7 +117,7 @@ class Question
*
* @return $this
*/
public function setHiddenFallback(bool $fallback)
public function setHiddenFallback(bool $fallback): static
{
$this->hiddenFallback = $fallback;
@@ -134,10 +126,8 @@ class Question
/**
* Gets values for the autocompleter.
*
* @return iterable|null
*/
public function getAutocompleterValues()
public function getAutocompleterValues(): ?iterable
{
$callback = $this->getAutocompleterCallback();
@@ -151,7 +141,7 @@ class Question
*
* @throws LogicException
*/
public function setAutocompleterValues(?iterable $values)
public function setAutocompleterValues(?iterable $values): static
{
if (\is_array($values)) {
$values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
@@ -162,7 +152,7 @@ class Question
} elseif ($values instanceof \Traversable) {
$valueCache = null;
$callback = static function () use ($values, &$valueCache) {
return $valueCache ?? $valueCache = iterator_to_array($values, false);
return $valueCache ??= iterator_to_array($values, false);
};
} else {
$callback = null;
@@ -186,13 +176,16 @@ class Question
*
* @return $this
*/
public function setAutocompleterCallback(callable $callback = null): self
public function setAutocompleterCallback(callable $callback = null): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
if ($this->hidden && null !== $callback) {
throw new LogicException('A hidden question cannot use the autocompleter.');
}
$this->autocompleterCallback = $callback;
$this->autocompleterCallback = null === $callback ? null : $callback(...);
return $this;
}
@@ -202,19 +195,20 @@ class Question
*
* @return $this
*/
public function setValidator(callable $validator = null)
public function setValidator(callable $validator = null): static
{
$this->validator = $validator;
if (1 > \func_num_args()) {
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
$this->validator = null === $validator ? null : $validator(...);
return $this;
}
/**
* Gets the validator for the question.
*
* @return callable|null
*/
public function getValidator()
public function getValidator(): ?callable
{
return $this->validator;
}
@@ -228,7 +222,7 @@ class Question
*
* @throws InvalidArgumentException in case the number of attempts is invalid
*/
public function setMaxAttempts(?int $attempts)
public function setMaxAttempts(?int $attempts): static
{
if (null !== $attempts && $attempts < 1) {
throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
@@ -243,10 +237,8 @@ class Question
* Gets the maximum number of attempts.
*
* Null means an unlimited number of attempts.
*
* @return int|null
*/
public function getMaxAttempts()
public function getMaxAttempts(): ?int
{
return $this->attempts;
}
@@ -258,9 +250,9 @@ class Question
*
* @return $this
*/
public function setNormalizer(callable $normalizer)
public function setNormalizer(callable $normalizer): static
{
$this->normalizer = $normalizer;
$this->normalizer = $normalizer(...);
return $this;
}
@@ -269,10 +261,8 @@ class Question
* Gets the normalizer for the response.
*
* The normalizer can ba a callable (a string), a closure or a class implementing __invoke.
*
* @return callable|null
*/
public function getNormalizer()
public function getNormalizer(): ?callable
{
return $this->normalizer;
}
@@ -290,7 +280,7 @@ class Question
/**
* @return $this
*/
public function setTrimmable(bool $trimmable): self
public function setTrimmable(bool $trimmable): static
{
$this->trimmable = $trimmable;