aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/question
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/question')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs46
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/question/question.rs21
2 files changed, 23 insertions, 44 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
index 9deec851..52316cf4 100644
--- a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
@@ -27,10 +27,9 @@ impl ChoiceQuestion {
default: Option<PhpMixed>,
) -> Result<Self, LogicException> {
if choices.is_empty() {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: "Choice question must have at least 1 choice available.".to_string(),
- code: 0,
- }));
+ return Err(LogicException::new(
+ "Choice question must have at least 1 choice available.".to_string(),
+ ));
}
let mut this = Self {
@@ -129,15 +128,10 @@ impl ChoiceQuestion {
&shirabe_php_shim::strval(&selected),
&mut matches,
) {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- &error_message,
- std::slice::from_ref(&selected),
- ),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(shirabe_php_shim::sprintf(
+ &error_message,
+ std::slice::from_ref(&selected),
+ )));
}
shirabe_php_shim::explode(",", &shirabe_php_shim::strval(&selected))
@@ -168,15 +162,10 @@ impl ChoiceQuestion {
}
if results.len() > 1 {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "The provided answer is ambiguous. Value should be one of \"{}\".",
- shirabe_php_shim::implode("\" or \"", &results),
- ),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(format!(
+ "The provided answer is ambiguous. Value should be one of \"{}\".",
+ shirabe_php_shim::implode("\" or \"", &results),
+ )));
}
// array_search($value, $choices)
@@ -210,15 +199,10 @@ impl ChoiceQuestion {
// false === $result
if matches!(result, PhpMixed::Bool(false)) {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- &error_message,
- std::slice::from_ref(value),
- ),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(shirabe_php_shim::sprintf(
+ &error_message,
+ std::slice::from_ref(value),
+ )));
}
// For associative choices, consistently return the key as string:
diff --git a/crates/shirabe-external-packages/src/symfony/console/question/question.rs b/crates/shirabe-external-packages/src/symfony/console/question/question.rs
index a96c3159..165f287e 100644
--- a/crates/shirabe-external-packages/src/symfony/console/question/question.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/question/question.rs
@@ -127,10 +127,9 @@ impl Question {
/// Throws LogicException in case the autocompleter is also used.
pub fn set_hidden(&mut self, hidden: bool) -> Result<&mut Self, LogicException> {
if self.autocompleter_callback.is_some() {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: "A hidden question cannot use the autocompleter.".to_string(),
- code: 0,
- }));
+ return Err(LogicException::new(
+ "A hidden question cannot use the autocompleter.".to_string(),
+ ));
}
self.hidden = hidden;
@@ -225,10 +224,9 @@ impl Question {
callback: Option<Box<dyn Fn(&str) -> Option<Vec<PhpMixed>>>>,
) -> Result<&mut Self, LogicException> {
if self.hidden && callback.is_some() {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: "A hidden question cannot use the autocompleter.".to_string(),
- code: 0,
- }));
+ return Err(LogicException::new(
+ "A hidden question cannot use the autocompleter.".to_string(),
+ ));
}
self.autocompleter_callback = callback;
@@ -267,11 +265,8 @@ impl Question {
if let Some(attempts) = attempts
&& attempts < 1
{
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: "Maximum number of attempts must be a positive value.".to_string(),
- code: 0,
- },
+ return Err(InvalidArgumentException::new(
+ "Maximum number of attempts must be a positive value.".to_string(),
));
}