Skip to content

Commit 1f8a525

Browse files
authored
Merge pull request #6 from MaplePHP/develop
Fix data type
2 parents 55bb4b1 + 6b7f4cc commit 1f8a525

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

Prompt.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ public function add(string $name, array $data): self
9898
* Prompt line, directly prompt line without data
9999
*
100100
* @param array $row
101-
* @return string|array|bool|int
101+
* @return mixed
102102
* @throws PromptException
103103
* @throws Exception
104104
*/
105-
public function promptLine(array $row): string|array|bool|int
105+
public function promptLine(array $row): mixed
106106
{
107107
$input = false;
108108
$default = $row['default'] ?? "";
@@ -113,7 +113,7 @@ public function promptLine(array $row): string|array|bool|int
113113
$rowType = $row['type'] ?? "text";
114114
$confirm = $row['confirm'] ?? false;
115115

116-
if (isset($default) && is_string($default)) {
116+
if (isset($default) && is_string($default) && strlen($default)) {
117117
$message .= " ($default)";
118118
}
119119

@@ -177,10 +177,7 @@ public function promptLine(array $row): string|array|bool|int
177177
if ($this->isEmpty($input)) {
178178
$input = $default;
179179
}
180-
181-
if (!(is_array($input) || is_string($input))) {
182-
throw new InvalidArgumentException("The input item is wrong input data type", 1);
183-
}
180+
184181
if (!(is_array($validate) || is_callable($validate))) {
185182
throw new InvalidArgumentException("The validate item is wrong input data type", 1);
186183
}
@@ -270,15 +267,14 @@ protected function isEmpty(mixed $input): bool
270267
* Validate a set of items
271268
*
272269
* @param array|callable $validate
273-
* @param string|array $input
274-
* @param array|null $error
275-
* @param-out null|string $error Error message or method that caused validation failure.
270+
* @param mixed $input
271+
* @param string|null $error
276272
* @return bool
277273
* @throws ErrorException
278274
*/
279-
protected function validateItems(array|callable $validate, string|array $input, ?array &$error = []): bool
275+
protected function validateItems(array|callable $validate, mixed $input, ?string &$error = ""): bool
280276
{
281-
$input = is_string($input) ? [$input] : $input;
277+
$input = (!is_array($input)) ? [$input] : $input;
282278
foreach ($input as $value) {
283279
if (is_callable($validate)) {
284280
$isValid = $validate($value);

examples/example.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,7 @@
2626
use MaplePHP\Prompts\Prompt;
2727
use MaplePHP\Prompts\Command;
2828
use MaplePHP\Prompts\SttyWrapper;
29-
// Define ANSI escape sequences for colors
30-
$limeGreenBackground = "\033[102m"; // Bright green background
31-
$grayText = "\e[90m"; // Bright black (gray) text
32-
$reset = "\e[0m"; // Reset colors
3329

34-
// Custom message with padding
35-
$message = " PASS ";
36-
37-
// Display the styled output in lime green with gray text
38-
echo "{$limeGreenBackground}{$grayText}{$message}{$reset} Tests\\Unit\\ExampleTest\n";
39-
40-
die;
4130
$command = new Command();
4231
$inp = new Prompt();
4332

@@ -86,7 +75,7 @@
8675
}
8776
],
8877
"message" => [
89-
"type" => "message", // Will be exclude form the end result array!
78+
"type" => "message", // Will be excluded form the end result array!
9079
"message" => "Lorem ipsum dolor",
9180
],
9281
"select" => [
@@ -123,7 +112,7 @@
123112
"confirm" => [
124113
"type" => "confirm",
125114
"message" => "Do you wish to continue?",
126-
"confirm" => "Continuing.."
115+
"confirm" => "Continuing..."
127116
]
128117
]);
129118

0 commit comments

Comments
 (0)