Update to laravel 7

This commit is contained in:
KodeStar
2022-03-10 11:54:29 +00:00
parent 61a5a1a8b0
commit f9a19fce91
7170 changed files with 274189 additions and 283773 deletions

View File

@@ -58,11 +58,9 @@ class ChoiceQuestion extends Question
*
* When multiselect is set to true, multiple choices can be answered.
*
* @param bool $multiselect
*
* @return $this
*/
public function setMultiselect($multiselect)
public function setMultiselect(bool $multiselect)
{
$this->multiselect = $multiselect;
$this->setValidator($this->getDefaultValidator());
@@ -93,11 +91,9 @@ class ChoiceQuestion extends Question
/**
* Sets the prompt for choices.
*
* @param string $prompt
*
* @return $this
*/
public function setPrompt($prompt)
public function setPrompt(string $prompt)
{
$this->prompt = $prompt;
@@ -109,11 +105,9 @@ class ChoiceQuestion extends Question
*
* The error message has a string placeholder (%s) for the invalid value.
*
* @param string $errorMessage
*
* @return $this
*/
public function setErrorMessage($errorMessage)
public function setErrorMessage(string $errorMessage)
{
$this->errorMessage = $errorMessage;
$this->setValidator($this->getDefaultValidator());
@@ -129,19 +123,23 @@ class ChoiceQuestion extends Question
$isAssoc = $this->isAssoc($choices);
return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) {
// Collapse all spaces.
$selectedChoices = str_replace(' ', '', $selected);
if ($multiselect) {
// Check for a separated comma values
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) {
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', (string) $selected, $matches)) {
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
}
$selectedChoices = explode(',', $selectedChoices);
$selectedChoices = explode(',', (string) $selected);
} else {
$selectedChoices = [$selected];
}
if ($this->isTrimmable()) {
foreach ($selectedChoices as $k => $v) {
$selectedChoices[$k] = trim((string) $v);
}
}
$multiselectChoices = [];
foreach ($selectedChoices as $value) {
$results = [];
@@ -152,7 +150,7 @@ class ChoiceQuestion extends Question
}
if (\count($results) > 1) {
throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results)));
throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of "%s".', implode('" or "', $results)));
}
$result = array_search($value, $choices);
@@ -171,7 +169,8 @@ class ChoiceQuestion extends Question
throw new InvalidArgumentException(sprintf($errorMessage, $value));
}
$multiselectChoices[] = (string) $result;
// For associative choices, consistently return the key as string:
$multiselectChoices[] = $isAssoc ? (string) $result : $result;
}
if ($multiselect) {

View File

@@ -35,10 +35,8 @@ class ConfirmationQuestion extends Question
/**
* Returns the default answer normalizer.
*
* @return callable
*/
private function getDefaultNormalizer()
private function getDefaultNormalizer(): callable
{
$default = $this->getDefault();
$regex = $this->trueAnswerRegex;

View File

@@ -29,10 +29,12 @@ class Question
private $validator;
private $default;
private $normalizer;
private $trimmable = true;
private $multiline = false;
/**
* @param string $question The question to ask to the user
* @param mixed $default The default answer to return if the user enters nothing
* @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)
{
@@ -53,13 +55,33 @@ class Question
/**
* Returns the default answer.
*
* @return mixed
* @return string|bool|int|float|null
*/
public function getDefault()
{
return $this->default;
}
/**
* Returns whether the user response accepts newline characters.
*/
public function isMultiline(): bool
{
return $this->multiline;
}
/**
* Sets whether the user response should accept newline characters.
*
* @return $this
*/
public function setMultiline(bool $multiline): self
{
$this->multiline = $multiline;
return $this;
}
/**
* Returns whether the user response must be hidden.
*
@@ -73,25 +95,23 @@ class Question
/**
* Sets whether the user response must be hidden or not.
*
* @param bool $hidden
*
* @return $this
*
* @throws LogicException In case the autocompleter is also used
*/
public function setHidden($hidden)
public function setHidden(bool $hidden)
{
if ($this->autocompleterCallback) {
throw new LogicException('A hidden question cannot use the autocompleter.');
}
$this->hidden = (bool) $hidden;
$this->hidden = $hidden;
return $this;
}
/**
* In case the response can not be hidden, whether to fallback on non-hidden question or not.
* In case the response cannot be hidden, whether to fallback on non-hidden question or not.
*
* @return bool
*/
@@ -101,15 +121,13 @@ class Question
}
/**
* Sets whether to fallback on non-hidden question if the response can not be hidden.
*
* @param bool $fallback
* Sets whether to fallback on non-hidden question if the response cannot be hidden.
*
* @return $this
*/
public function setHiddenFallback($fallback)
public function setHiddenFallback(bool $fallback)
{
$this->hiddenFallback = (bool) $fallback;
$this->hiddenFallback = $fallback;
return $this;
}
@@ -129,14 +147,11 @@ class Question
/**
* Sets values for the autocompleter.
*
* @param iterable|null $values
*
* @return $this
*
* @throws InvalidArgumentException
* @throws LogicException
*/
public function setAutocompleterValues($values)
public function setAutocompleterValues(?iterable $values)
{
if (\is_array($values)) {
$values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
@@ -149,10 +164,8 @@ class Question
$callback = static function () use ($values, &$valueCache) {
return $valueCache ?? $valueCache = iterator_to_array($values, false);
};
} elseif (null === $values) {
$callback = null;
} else {
throw new InvalidArgumentException('Autocompleter values can be either an array, "null" or a "Traversable" object.');
$callback = null;
}
return $this->setAutocompleterCallback($callback);
@@ -187,8 +200,6 @@ class Question
/**
* Sets a validator for the question.
*
* @param callable|null $validator
*
* @return $this
*/
public function setValidator(callable $validator = null)
@@ -213,13 +224,11 @@ class Question
*
* Null means an unlimited number of attempts.
*
* @param int|null $attempts
*
* @return $this
*
* @throws InvalidArgumentException in case the number of attempts is invalid
*/
public function setMaxAttempts($attempts)
public function setMaxAttempts(?int $attempts)
{
if (null !== $attempts && $attempts < 1) {
throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
@@ -247,8 +256,6 @@ class Question
*
* The normalizer can be a callable (a string), a closure or a class implementing __invoke.
*
* @param callable $normalizer
*
* @return $this
*/
public function setNormalizer(callable $normalizer)
@@ -263,15 +270,30 @@ class Question
*
* The normalizer can ba a callable (a string), a closure or a class implementing __invoke.
*
* @return callable
* @return callable|null
*/
public function getNormalizer()
{
return $this->normalizer;
}
protected function isAssoc($array)
protected function isAssoc(array $array)
{
return (bool) \count(array_filter(array_keys($array), 'is_string'));
}
public function isTrimmable(): bool
{
return $this->trimmable;
}
/**
* @return $this
*/
public function setTrimmable(bool $trimmable): self
{
$this->trimmable = $trimmable;
return $this;
}
}