aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-08 22:14:12 +0900
committernsfisis <nsfisis@gmail.com>2026-08-08 22:14:12 +0900
commitf4cad2123b2af0de72bda4ce039e16e74f163f4e (patch)
tree21803308c5ff41e23c9d3b117433eea16b4ff663 /crates/shirabe-external-packages/src/symfony/console
parent0209f63210e5b547b5c6b73367bb80ea86c255ec (diff)
downloadphp-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.tar.gz
php-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.tar.zst
php-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.zip
feat(php-shim): give ported exceptions PHP's class hierarchy
Ported exceptions were flat structs reached with `downcast_ref`, so Composer's `catch (\RuntimeException $e)` only matched the exact leaf type and `get_class($e)` had nothing to report. Each exception now embeds an instance of the class it extends and travels inside an `AnyThrowable`; `Catch::catch`/`catch_mut` walk that chain, and `PhpClass::php_class_name` yields the PHP FQCN. Dropping the `std::error::Error` impls from the exception types leaves `AnyThrowable` as the only route into an `anyhow::Error`, so the walk cannot be bypassed. A `no_exception_downcast` linter catches the `downcast::<X>()` calls that would now silently answer `None`. Three sites change behavior as a result: the `TransportException` exit-code override reaches `MaxFileSizeExceededException`, the `catch (\LogicException)` in findSimilar() reaches its subclasses, and rendered exception titles carry the real class name rather than a guess. `get_class_err()` is no longer a `todo!()`, which re-enables FilesystemRepositoryTest::testCorruptedRepositoryFile. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/color.rs52
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/command/command.rs23
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs36
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/exception/command_not_found_exception.rs20
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/exception/exception_interface.rs2
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/exception/invalid_argument_exception.rs12
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/exception/invalid_option_exception.rs14
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/exception/logic_exception.rs12
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/exception/missing_input_exception.rs12
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/exception/namespace_not_found_exception.rs12
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/exception/runtime_exception.rs12
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs14
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_stack.rs7
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs12
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs11
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs15
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs45
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs2
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/table.rs33
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs21
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs26
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/table_style.rs16
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs52
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/array_input.rs36
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/input.rs59
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/input_argument.rs28
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs120
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/input_option.rs60
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/string_input.rs15
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs8
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs14
-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
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs7
34 files changed, 348 insertions, 527 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/color.rs b/crates/shirabe-external-packages/src/symfony/console/color.rs
index 79d0c58b..f1aa4332 100644
--- a/crates/shirabe-external-packages/src/symfony/console/color.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/color.rs
@@ -75,22 +75,17 @@ impl Color {
for option in options {
let available = available_options_get(option);
if available.is_none() {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "Invalid option specified: \"{}\". Expected one of ({}).",
- option.clone(),
- shirabe_php_shim::implode(
- ", ",
- &AVAILABLE_OPTIONS
- .iter()
- .map(|(k, _)| k.to_string())
- .collect::<Vec<String>>(),
- ),
- ),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(format!(
+ "Invalid option specified: \"{}\". Expected one of ({}).",
+ option.clone(),
+ shirabe_php_shim::implode(
+ ", ",
+ &AVAILABLE_OPTIONS
+ .iter()
+ .map(|(k, _)| k.to_string())
+ .collect::<Vec<String>>(),
+ ),
+ )));
}
this.options.insert(option.clone(), available.unwrap());
@@ -153,12 +148,10 @@ impl Color {
}
if shirabe_php_shim::strlen(&color) != 6 {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!("Invalid \"{}\" color.", color),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(format!(
+ "Invalid \"{}\" color.",
+ color
+ )));
}
return Ok(format!(
@@ -178,16 +171,11 @@ impl Color {
let mut available: Vec<String> = COLORS.iter().map(|(k, _)| k.to_string()).collect();
available.extend(BRIGHT_COLORS.iter().map(|(k, _)| k.to_string()));
- Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "Invalid \"{}\" color; expected one of ({}).",
- color,
- shirabe_php_shim::implode(", ", &available),
- ),
- code: 0,
- },
- ))
+ Err(InvalidArgumentException::new(format!(
+ "Invalid \"{}\" color; expected one of ({}).",
+ color,
+ shirabe_php_shim::implode(", ", &available),
+ )))
}
fn convert_hex_color_to_ansi(color: i64) -> String {
diff --git a/crates/shirabe-external-packages/src/symfony/console/command/command.rs b/crates/shirabe-external-packages/src/symfony/console/command/command.rs
index ca61717d..a1636848 100644
--- a/crates/shirabe-external-packages/src/symfony/console/command/command.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/command/command.rs
@@ -138,12 +138,10 @@ impl CommandData {
let mut matches: Vec<Option<String>> = Vec::new();
if !shirabe_php_shim::preg_match(php_regex!(r"/^[^\:]++(\:[^\:]++)*$/"), name, &mut matches)
{
- return Ok(Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!("Command name \"{}\" is invalid.", name),
- code: 0,
- },
- )));
+ return Ok(Err(InvalidArgumentException::new(format!(
+ "Command name \"{}\" is invalid.",
+ name
+ ))));
}
Ok(Ok(()))
@@ -847,14 +845,11 @@ impl Command for CommandData {
let helper_set = match &*helper_set_ref {
None => {
return Ok(Err(
- crate::symfony::console::exception::logic_exception::LogicException(
- shirabe_php_shim::LogicException {
- message: format!(
- "Cannot retrieve helper \"{}\" because there is no HelperSet defined. Did you forget to add your command to the application or to set the application on the command using the setApplication() method? You can also set the HelperSet directly using the setHelperSet() method.",
- name
- ),
- code: 0,
- },
+ crate::symfony::console::exception::logic_exception::LogicException::new(
+ format!(
+ "Cannot retrieve helper \"{}\" because there is no HelperSet defined. Did you forget to add your command to the application or to set the application on the command using the setApplication() method? You can also set the HelperSet directly using the setHelperSet() method.",
+ name
+ ),
),
));
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs b/crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs
index cc8747ec..5854e248 100644
--- a/crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs
@@ -81,11 +81,9 @@ impl CompleteCommand {
) -> anyhow::Result<CompletionInput> {
let current_index = input.get_option("current")?;
if !current_index.to_bool() || !shirabe_php_shim::ctype_digit(&current_index.to_string()) {
- anyhow::bail!(shirabe_php_shim::RuntimeException {
- message: "The \"--current\" option must be set and it must be an integer."
- .to_string(),
- code: 0,
- });
+ anyhow::bail!(shirabe_php_shim::RuntimeException::new(
+ "The \"--current\" option must be set and it must be an integer.".to_string()
+ ));
}
let tokens: Vec<String> = match input.get_option("input")?.as_list() {
@@ -251,10 +249,9 @@ impl Command for CompleteCommand {
let shell = input.borrow().get_option("shell")?;
if !shell.to_bool() {
- anyhow::bail!(shirabe_php_shim::RuntimeException {
- message: "The \"--shell\" option must be set.".to_string(),
- code: 0,
- });
+ anyhow::bail!(shirabe_php_shim::RuntimeException::new(
+ "The \"--shell\" option must be set.".to_string()
+ ));
}
let completion_output = self
@@ -263,18 +260,15 @@ impl Command for CompleteCommand {
.cloned()
.unwrap_or(PhpMixed::Bool(false));
if !completion_output.to_bool() {
- anyhow::bail!(shirabe_php_shim::RuntimeException {
- message: format!(
- "Shell completion is not supported for your shell: \"{}\" (supported: \"{}\").",
- shell,
- self.completion_outputs
- .keys()
- .cloned()
- .collect::<Vec<_>>()
- .join("\", \"")
- ),
- code: 0,
- });
+ anyhow::bail!(shirabe_php_shim::RuntimeException::new(format!(
+ "Shell completion is not supported for your shell: \"{}\" (supported: \"{}\").",
+ shell,
+ self.completion_outputs
+ .keys()
+ .cloned()
+ .collect::<Vec<_>>()
+ .join("\", \"")
+ )));
}
let mut completion_input = self.create_completion_input(&*input.borrow())?;
diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/command_not_found_exception.rs b/crates/shirabe-external-packages/src/symfony/console/exception/command_not_found_exception.rs
index 5a6959d4..4b27c5e6 100644
--- a/crates/shirabe-external-packages/src/symfony/console/exception/command_not_found_exception.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/exception/command_not_found_exception.rs
@@ -1,21 +1,17 @@
//! ref: composer/vendor/symfony/console/Exception/CommandNotFoundException.php
use super::exception_interface::ExceptionInterface;
-use super::invalid_argument_exception::InvalidArgumentException;
#[derive(Debug)]
pub struct CommandNotFoundException {
- inner: InvalidArgumentException,
+ inner: shirabe_php_shim::InvalidArgumentException,
alternatives: Vec<String>,
}
impl CommandNotFoundException {
pub fn new(message: String, alternatives: Vec<String>, code: i64) -> Self {
Self {
- inner: InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message,
- code,
- }),
+ inner: shirabe_php_shim::InvalidArgumentException::with_code(message, code),
alternatives,
}
}
@@ -25,12 +21,10 @@ impl CommandNotFoundException {
}
}
-impl std::fmt::Display for CommandNotFoundException {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", self.inner)
- }
-}
-
-impl std::error::Error for CommandNotFoundException {}
+shirabe_php_shim::impl_php_exception!(
+ CommandNotFoundException,
+ inner,
+ r"Symfony\Component\Console\Exception\CommandNotFoundException"
+);
impl ExceptionInterface for CommandNotFoundException {}
diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/exception_interface.rs b/crates/shirabe-external-packages/src/symfony/console/exception/exception_interface.rs
index ce279fdb..bb2200f6 100644
--- a/crates/shirabe-external-packages/src/symfony/console/exception/exception_interface.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/exception/exception_interface.rs
@@ -1,3 +1,3 @@
//! ref: composer/vendor/symfony/console/Exception/ExceptionInterface.php
-pub trait ExceptionInterface: std::error::Error {}
+pub trait ExceptionInterface: shirabe_php_shim::Throwable {}
diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/invalid_argument_exception.rs b/crates/shirabe-external-packages/src/symfony/console/exception/invalid_argument_exception.rs
index ac3be3b2..ced79b44 100644
--- a/crates/shirabe-external-packages/src/symfony/console/exception/invalid_argument_exception.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/exception/invalid_argument_exception.rs
@@ -5,12 +5,16 @@ use super::exception_interface::ExceptionInterface;
#[derive(Debug)]
pub struct InvalidArgumentException(pub shirabe_php_shim::InvalidArgumentException);
-impl std::fmt::Display for InvalidArgumentException {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", self.0)
+impl InvalidArgumentException {
+ pub fn new(message: String) -> Self {
+ Self(shirabe_php_shim::InvalidArgumentException::new(message))
}
}
-impl std::error::Error for InvalidArgumentException {}
+shirabe_php_shim::impl_php_exception!(
+ InvalidArgumentException,
+ 0,
+ r"Symfony\Component\Console\Exception\InvalidArgumentException"
+);
impl ExceptionInterface for InvalidArgumentException {}
diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/invalid_option_exception.rs b/crates/shirabe-external-packages/src/symfony/console/exception/invalid_option_exception.rs
index 2cc23817..04de3d42 100644
--- a/crates/shirabe-external-packages/src/symfony/console/exception/invalid_option_exception.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/exception/invalid_option_exception.rs
@@ -1,17 +1,21 @@
//! ref: composer/vendor/symfony/console/Exception/InvalidOptionException.php
use super::exception_interface::ExceptionInterface;
-use super::invalid_argument_exception::InvalidArgumentException;
+use shirabe_php_shim::InvalidArgumentException;
#[derive(Debug)]
pub struct InvalidOptionException(pub InvalidArgumentException);
-impl std::fmt::Display for InvalidOptionException {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", self.0)
+impl InvalidOptionException {
+ pub fn new(message: String) -> Self {
+ Self(InvalidArgumentException::new(message))
}
}
-impl std::error::Error for InvalidOptionException {}
+shirabe_php_shim::impl_php_exception!(
+ InvalidOptionException,
+ 0,
+ r"Symfony\Component\Console\Exception\InvalidOptionException"
+);
impl ExceptionInterface for InvalidOptionException {}
diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/logic_exception.rs b/crates/shirabe-external-packages/src/symfony/console/exception/logic_exception.rs
index 2c782195..03d9241f 100644
--- a/crates/shirabe-external-packages/src/symfony/console/exception/logic_exception.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/exception/logic_exception.rs
@@ -5,12 +5,16 @@ use super::exception_interface::ExceptionInterface;
#[derive(Debug)]
pub struct LogicException(pub shirabe_php_shim::LogicException);
-impl std::fmt::Display for LogicException {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", self.0)
+impl LogicException {
+ pub fn new(message: String) -> Self {
+ Self(shirabe_php_shim::LogicException::new(message))
}
}
-impl std::error::Error for LogicException {}
+shirabe_php_shim::impl_php_exception!(
+ LogicException,
+ 0,
+ r"Symfony\Component\Console\Exception\LogicException"
+);
impl ExceptionInterface for LogicException {}
diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/missing_input_exception.rs b/crates/shirabe-external-packages/src/symfony/console/exception/missing_input_exception.rs
index 65474c2b..f9ddc0e6 100644
--- a/crates/shirabe-external-packages/src/symfony/console/exception/missing_input_exception.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/exception/missing_input_exception.rs
@@ -6,12 +6,16 @@ use super::runtime_exception::RuntimeException;
#[derive(Debug)]
pub struct MissingInputException(pub RuntimeException);
-impl std::fmt::Display for MissingInputException {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", self.0)
+impl MissingInputException {
+ pub fn new(message: String) -> Self {
+ Self(RuntimeException::new(message))
}
}
-impl std::error::Error for MissingInputException {}
+shirabe_php_shim::impl_php_exception!(
+ MissingInputException,
+ 0,
+ r"Symfony\Component\Console\Exception\MissingInputException"
+);
impl ExceptionInterface for MissingInputException {}
diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/namespace_not_found_exception.rs b/crates/shirabe-external-packages/src/symfony/console/exception/namespace_not_found_exception.rs
index c593a3f7..31da0305 100644
--- a/crates/shirabe-external-packages/src/symfony/console/exception/namespace_not_found_exception.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/exception/namespace_not_found_exception.rs
@@ -6,12 +6,16 @@ use super::exception_interface::ExceptionInterface;
#[derive(Debug)]
pub struct NamespaceNotFoundException(pub CommandNotFoundException);
-impl std::fmt::Display for NamespaceNotFoundException {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", self.0)
+impl NamespaceNotFoundException {
+ pub fn new(message: String, alternatives: Vec<String>, code: i64) -> Self {
+ Self(CommandNotFoundException::new(message, alternatives, code))
}
}
-impl std::error::Error for NamespaceNotFoundException {}
+shirabe_php_shim::impl_php_exception!(
+ NamespaceNotFoundException,
+ 0,
+ r"Symfony\Component\Console\Exception\NamespaceNotFoundException"
+);
impl ExceptionInterface for NamespaceNotFoundException {}
diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/runtime_exception.rs b/crates/shirabe-external-packages/src/symfony/console/exception/runtime_exception.rs
index cfc64774..12e5b79c 100644
--- a/crates/shirabe-external-packages/src/symfony/console/exception/runtime_exception.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/exception/runtime_exception.rs
@@ -5,12 +5,16 @@ use super::exception_interface::ExceptionInterface;
#[derive(Debug)]
pub struct RuntimeException(pub shirabe_php_shim::RuntimeException);
-impl std::fmt::Display for RuntimeException {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", self.0)
+impl RuntimeException {
+ pub fn new(message: String) -> Self {
+ Self(shirabe_php_shim::RuntimeException::new(message))
}
}
-impl std::error::Error for RuntimeException {}
+shirabe_php_shim::impl_php_exception!(
+ RuntimeException,
+ 0,
+ r"Symfony\Component\Console\Exception\RuntimeException"
+);
impl ExceptionInterface for RuntimeException {}
diff --git a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs
index f8a5db4c..a0562aef 100644
--- a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs
@@ -253,15 +253,11 @@ impl OutputFormatterInterface for OutputFormatter {
) -> anyhow::Result<std::rc::Rc<std::cell::RefCell<Box<dyn OutputFormatterStyleInterface>>>>
{
if !self.has_style(name) {
- return Err(anyhow::anyhow!(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "Undefined style: \"{}\".",
- shirabe_php_shim::PhpMixed::String(name.to_string()),
- ),
- code: 0,
- },
- )));
+ return Err(InvalidArgumentException::new(format!(
+ "Undefined style: \"{}\".",
+ shirabe_php_shim::PhpMixed::String(name.to_string()),
+ ))
+ .into());
}
Ok(std::rc::Rc::clone(
diff --git a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_stack.rs b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_stack.rs
index 2464c028..acfd8878 100644
--- a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_stack.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_stack.rs
@@ -57,11 +57,8 @@ impl OutputFormatterStyleStack {
}
}
- Ok(Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: "Incorrectly nested style tag found.".to_string(),
- code: 0,
- },
+ Ok(Err(InvalidArgumentException::new(
+ "Incorrectly nested style tag found.".to_string(),
)))
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs
index 05f0d7d1..36603b06 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs
@@ -79,13 +79,11 @@ impl DescriptorHelper {
};
if !self.descriptors.contains_key(&format) {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("Unsupported format \"{}\".", format.clone()),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "Unsupported format \"{}\".",
+ format.clone()
+ ))
+ .into());
}
let descriptor = self.descriptors.get_mut(&format).unwrap();
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs
index 312d8e15..0f81348d 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs
@@ -103,13 +103,10 @@ impl ProcessHelper {
};
}
None => {
- anyhow::bail!(shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "Invalid command provided to \"{}()\": the command should be an array whose first element is either the path to the binary to run or a \"Process\" object.",
- shirabe_php_shim::PhpMixed::String("ProcessHelper::run".to_string()),
- ),
- code: 0,
- });
+ anyhow::bail!(shirabe_php_shim::InvalidArgumentException::new(format!(
+ "Invalid command provided to \"{}()\": the command should be an array whose first element is either the path to the binary to run or a \"Process\" object.",
+ shirabe_php_shim::PhpMixed::String("ProcessHelper::run".to_string()),
+ )));
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs
index 0abee1e7..7bfbfbcd 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs
@@ -642,10 +642,7 @@ impl ProgressBar {
"remaining".to_string(),
Box::new(|bar: &ProgressBar, _output: &std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>| {
if bar.get_max_steps() == 0 {
- return Ok(Err(LogicException(shirabe_php_shim::LogicException {
- message: "Unable to display the remaining time if the maximum number of steps is not set.".to_string(),
- code: 0,
- })));
+ return Ok(Err(LogicException::new("Unable to display the remaining time if the maximum number of steps is not set.".to_string())));
}
Ok(Ok(shirabe_php_shim::PhpMixed::String(
@@ -658,10 +655,7 @@ impl ProgressBar {
"estimated".to_string(),
Box::new(|bar: &ProgressBar, _output: &std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>| {
if bar.get_max_steps() == 0 {
- return Ok(Err(LogicException(shirabe_php_shim::LogicException {
- message: "Unable to display the estimated time if the maximum number of steps is not set.".to_string(),
- code: 0,
- })));
+ return Ok(Err(LogicException::new("Unable to display the estimated time if the maximum number of steps is not set.".to_string())));
}
Ok(Ok(shirabe_php_shim::PhpMixed::String(
@@ -814,10 +808,7 @@ impl ProgressBar {
let formatter = formatters.as_ref().unwrap().get(&name).unwrap();
formatter(self, &self.output)
});
- match formatter_result? {
- Ok(text) => text,
- Err(e) => return Err(anyhow::Error::new(e)),
- }
+ formatter_result??
} else if let Some(message) = self.messages.get(&name) {
shirabe_php_shim::PhpMixed::String(message.clone())
} else {
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
index 987c43f1..2091225d 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
@@ -185,12 +185,7 @@ pub trait QuestionHelperInterface {
}
if matches!(read, PhpMixed::Bool(false)) {
- return Ok(Err(MissingInputException(RuntimeException(
- shirabe_php_shim::RuntimeException {
- message: "Aborted.".to_string(),
- code: 0,
- },
- ))));
+ return Ok(Err(MissingInputException::new("Aborted.".to_string())));
}
r = read;
if question.is_trimmable() {
@@ -263,17 +258,19 @@ pub trait QuestionHelperInterface {
// The validator return type is fixed to InvalidArgumentException here, so the
// RuntimeException rethrow branch is statically unreachable; record the error
// and retry.
- error = Some(shirabe_php_shim::Exception {
- message: e.0.message.clone(),
- code: e.0.code,
- });
+ error = Some(shirabe_php_shim::Exception::with_code(
+ e.get_message().to_string(),
+ e.get_code(),
+ ));
}
}
}
// throw $error;
Err(anyhow::Error::msg(
- error.map(|e| e.message).unwrap_or_default(),
+ error
+ .map(|e| e.get_message().to_string())
+ .unwrap_or_default(),
))
}
@@ -415,12 +412,12 @@ impl QuestionHelper {
let formatter = helper_set.borrow().get_formatter();
formatter.borrow().format_block(
- FormatBlockMessages::String(error.message.clone()),
+ FormatBlockMessages::String(error.get_message().to_string()),
"error",
false,
)
} else {
- format!("<error>{}</error>", error.message)
+ format!("<error>{}</error>", error.get_message())
};
output
@@ -491,12 +488,7 @@ impl QuestionHelper {
&& matches!(question.get_default(), PhpMixed::Null))
{
shirabe_php_shim::shell_exec(&format!("stty {}", stty_mode));
- return Err(MissingInputException(RuntimeException(
- shirabe_php_shim::RuntimeException {
- message: "Aborted.".to_string(),
- code: 0,
- },
- )));
+ return Err(MissingInputException::new("Aborted.".to_string()));
} else if c.as_deref() == Some("\u{7f}") {
// Backspace Character
if 0 == num_matches && 0 != i {
@@ -730,10 +722,9 @@ impl QuestionHelper {
stty_mode = shirabe_php_shim::shell_exec("stty -g").unwrap_or_default();
shirabe_php_shim::shell_exec("stty -echo");
} else if self.is_interactive_input(input_stream) {
- return Ok(Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: "Unable to hide the response.".to_string(),
- code: 0,
- })));
+ return Ok(Err(RuntimeException::new(
+ "Unable to hide the response.".to_string(),
+ )));
}
let value = shirabe_php_shim::fgets(input_stream, Some(4096));
@@ -745,13 +736,7 @@ impl QuestionHelper {
let mut value = match value {
Some(value) => value,
None => {
- return Err(MissingInputException(RuntimeException(
- shirabe_php_shim::RuntimeException {
- message: "Aborted.".to_string(),
- code: 0,
- },
- ))
- .into());
+ return Err(MissingInputException::new("Aborted.".to_string()).into());
}
};
if trimmable {
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
index cae3434d..eda54243 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
@@ -138,7 +138,7 @@ impl QuestionHelperInterface for SymfonyQuestionHelper {
let mut borrowed = output.borrow_mut();
if let Some(style) = (*borrowed).as_any_mut().downcast_mut::<SymfonyStyle>() {
style.new_line(1);
- style.error(PhpMixed::String(error.message.clone()));
+ style.error(PhpMixed::String(error.get_message().to_string()));
return;
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
index 66ab3174..a1f5a11e 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
@@ -325,12 +325,10 @@ impl Table {
return Ok(Ok(style.clone()));
}
- Ok(Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!("Style \"{}\" is not defined.", name),
- code: 0,
- },
- )))
+ Ok(Err(InvalidArgumentException::new(format!(
+ "Style \"{}\" is not defined.",
+ name
+ ))))
}
/// Sets table style.
@@ -454,14 +452,11 @@ impl Table {
/// Adds a row to the table, and re-renders the table.
pub fn append_row(&mut self, row: Row) -> anyhow::Result<Result<&mut Self, RuntimeException>> {
if !Self::output_is_console_section(&self.output) {
- return Ok(Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: format!(
- "Output should be an instance of \"{}\" when calling \"{}\".",
- "Symfony\\Component\\Console\\Output\\ConsoleSectionOutput",
- "Symfony\\Component\\Console\\Helper\\Table::appendRow",
- ),
- code: 0,
- })));
+ return Ok(Err(RuntimeException::new(format!(
+ "Output should be an instance of \"{}\" when calling \"{}\".",
+ "Symfony\\Component\\Console\\Output\\ConsoleSectionOutput",
+ "Symfony\\Component\\Console\\Helper\\Table::appendRow",
+ ))));
}
if self.rendered {
@@ -1373,12 +1368,10 @@ impl Table {
return Ok(Ok(style.clone()));
}
- Ok(Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!("Style \"{}\" is not defined.", name),
- code: 0,
- },
- )))
+ Ok(Err(InvalidArgumentException::new(format!(
+ "Style \"{}\" is not defined.",
+ name
+ ))))
}
fn formatter_is_wrappable(
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs
index 2b1e592b..c899e5f7 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs
@@ -35,27 +35,18 @@ impl TableCell {
.cloned()
.collect();
if !diff.is_empty() {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "The TableCell does not support the following options: '{}'.",
- diff.join("', '"),
- ),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(format!(
+ "The TableCell does not support the following options: '{}'.",
+ diff.join("', '"),
+ )));
}
if let Some(style) = options.get("style")
&& !matches!(style, TableCellOption::Style(_))
&& !matches!(style, TableCellOption::Null)
{
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: "The style option must be an instance of \"TableCellStyle\"."
- .to_string(),
- code: 0,
- },
+ return Err(InvalidArgumentException::new(
+ "The style option must be an instance of \"TableCellStyle\".".to_string(),
));
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs
index b48b6518..df24b404 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs
@@ -52,15 +52,10 @@ impl TableCellStyle {
.cloned()
.collect();
if !diff.is_empty() {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "The TableCellStyle does not support the following options: '{}'.",
- diff.join("', '"),
- ),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(format!(
+ "The TableCellStyle does not support the following options: '{}'.",
+ diff.join("', '"),
+ )));
}
if let Some(align) = options.get("align") {
@@ -69,15 +64,10 @@ impl TableCellStyle {
_ => String::new(),
};
if align_map(&align).is_none() {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "Wrong align value. Value must be following: '{}'.",
- align_map_keys().join("', '"),
- ),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(format!(
+ "Wrong align value. Value must be following: '{}'.",
+ align_map_keys().join("', '"),
+ )));
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table_style.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table_style.rs
index a215b989..bbe899af 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/table_style.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/table_style.rs
@@ -70,10 +70,9 @@ impl TableStyle {
padding_char: String,
) -> anyhow::Result<Result<&mut Self, LogicException>> {
if padding_char.is_empty() {
- return Ok(Err(LogicException(shirabe_php_shim::LogicException {
- message: "The padding char must not be empty.".to_string(),
- code: 0,
- })));
+ return Ok(Err(LogicException::new(
+ "The padding char must not be empty.".to_string(),
+ )));
}
self.padding_char = padding_char;
@@ -254,13 +253,8 @@ impl TableStyle {
]
.contains(&pad_type)
{
- return Ok(Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: "Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH)."
- .to_string(),
- code: 0,
- },
- )));
+ return Ok(Err(InvalidArgumentException::new("Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH)."
+ .to_string())));
}
self.pad_type = pad_type;
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
index fdc2dcc2..65ab9053 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
@@ -169,10 +169,10 @@ impl ArgvInput {
shirabe_php_shim::mb_substr(name, i, Some(1), Some(&encoding))
}
};
- return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: format!("The \"-{}\" option does not exist.", bad),
- code: 0,
- })
+ return Err(RuntimeException::new(format!(
+ "The \"-{}\" option does not exist.",
+ bad
+ ))
.into());
}
@@ -292,9 +292,7 @@ impl ArgvInput {
format!("No arguments expected, got \"{}\".", token)
};
- return Err(
- RuntimeException(shirabe_php_shim::RuntimeException { message, code: 0 }).into(),
- );
+ return Err(RuntimeException::new(message).into());
}
Ok(())
@@ -303,10 +301,10 @@ impl ArgvInput {
/// Adds a short option value.
fn add_short_option(&mut self, shortcut: &str, value: PhpMixed) -> anyhow::Result<()> {
if !self.inner.definition.has_shortcut(shortcut) {
- return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: format!("The \"-{}\" option does not exist.", shortcut),
- code: 0,
- })
+ return Err(RuntimeException::new(format!(
+ "The \"-{}\" option does not exist.",
+ shortcut
+ ))
.into());
}
@@ -323,19 +321,19 @@ impl ArgvInput {
fn add_long_option(&mut self, name: &str, mut value: PhpMixed) -> anyhow::Result<()> {
if !self.inner.definition.has_option(name) {
if !self.inner.definition.has_negation(name) {
- return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: format!("The \"--{}\" option does not exist.", name),
- code: 0,
- })
+ return Err(RuntimeException::new(format!(
+ "The \"--{}\" option does not exist.",
+ name
+ ))
.into());
}
let option_name = self.inner.definition.negation_to_name(name)?;
if !matches!(value, PhpMixed::Null) {
- return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: format!("The \"--{}\" option does not accept a value.", name),
- code: 0,
- })
+ return Err(RuntimeException::new(format!(
+ "The \"--{}\" option does not accept a value.",
+ name
+ ))
.into());
}
self.inner
@@ -348,10 +346,10 @@ impl ArgvInput {
let option = self.inner.definition.get_option(name)?;
if !matches!(value, PhpMixed::Null) && !option.accept_value() {
- return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: format!("The \"--{}\" option does not accept a value.", name),
- code: 0,
- })
+ return Err(RuntimeException::new(format!(
+ "The \"--{}\" option does not accept a value.",
+ name
+ ))
.into());
}
@@ -373,10 +371,10 @@ impl ArgvInput {
if matches!(value, PhpMixed::Null) {
if option.is_value_required() {
- return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: format!("The \"--{}\" option requires a value.", name),
- code: 0,
- })
+ return Err(RuntimeException::new(format!(
+ "The \"--{}\" option requires a value.",
+ name
+ ))
.into());
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
index 9a19b839..de89a340 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
@@ -154,11 +154,9 @@ impl ArrayInput {
/// Adds a short option value.
fn add_short_option(&mut self, shortcut: &str, value: PhpMixed) -> anyhow::Result<()> {
if !self.inner.definition.has_shortcut(shortcut) {
- return Err(InvalidOptionException(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"-{}\" option does not exist.", shortcut),
- code: 0,
- },
+ return Err(InvalidOptionException::new(format!(
+ "The \"-{}\" option does not exist.",
+ shortcut
))
.into());
}
@@ -176,11 +174,9 @@ impl ArrayInput {
fn add_long_option(&mut self, name: &str, mut value: PhpMixed) -> anyhow::Result<()> {
if !self.inner.definition.has_option(name) {
if !self.inner.definition.has_negation(name) {
- return Err(InvalidOptionException(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"--{}\" option does not exist.", name),
- code: 0,
- },
+ return Err(InvalidOptionException::new(format!(
+ "The \"--{}\" option does not exist.",
+ name
))
.into());
}
@@ -197,11 +193,9 @@ impl ArrayInput {
if matches!(value, PhpMixed::Null) {
if option.is_value_required() {
- return Err(InvalidOptionException(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"--{}\" option requires a value.", name),
- code: 0,
- },
+ return Err(InvalidOptionException::new(format!(
+ "The \"--{}\" option requires a value.",
+ name
))
.into());
}
@@ -219,13 +213,11 @@ impl ArrayInput {
/// Adds an argument value.
fn add_argument(&mut self, name: &PhpMixed, value: PhpMixed) -> anyhow::Result<()> {
if !self.inner.definition.has_argument(name) {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"{}\" argument does not exist.", name.clone()),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "The \"{}\" argument does not exist.",
+ name.clone()
+ ))
+ .into());
}
self.inner
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input.rs b/crates/shirabe-external-packages/src/symfony/console/input/input.rs
index e14ed354..ceff85f6 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/input.rs
@@ -80,13 +80,10 @@ impl Input {
);
if !missing_arguments.is_empty() {
- return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: format!(
- "Not enough arguments (missing: \"{}\").",
- shirabe_php_shim::implode(", ", &missing_arguments),
- ),
- code: 0,
- })
+ return Err(RuntimeException::new(format!(
+ "Not enough arguments (missing: \"{}\").",
+ shirabe_php_shim::implode(", ", &missing_arguments),
+ ))
.into());
}
@@ -113,13 +110,11 @@ impl Input {
.definition
.has_argument(&PhpMixed::String(name.to_string()))
{
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"{}\" argument does not exist.", name),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "The \"{}\" argument does not exist.",
+ name
+ ))
+ .into());
}
Ok(match self.arguments.get(name) {
@@ -137,13 +132,11 @@ impl Input {
.definition
.has_argument(&PhpMixed::String(name.to_string()))
{
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"{}\" argument does not exist.", name),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "The \"{}\" argument does not exist.",
+ name
+ ))
+ .into());
}
self.arguments.insert(name.to_string(), value);
@@ -174,13 +167,11 @@ impl Input {
}
if !self.definition.has_option(name) {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"{}\" option does not exist.", name),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "The \"{}\" option does not exist.",
+ name
+ ))
+ .into());
}
Ok(if self.options.contains_key(name) {
@@ -198,13 +189,11 @@ impl Input {
return Ok(());
} else if !self.definition.has_option(name) {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"{}\" option does not exist.", name),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "The \"{}\" option does not exist.",
+ name
+ ))
+ .into());
}
self.options.insert(name.to_string(), value);
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_argument.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_argument.rs
index 4a732bd8..35f62389 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/input_argument.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/input_argument.rs
@@ -26,13 +26,11 @@ impl InputArgument {
let mode = match mode {
None => Self::OPTIONAL,
Some(m) if !(1..=7).contains(&m) => {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("Argument mode \"{}\" is not valid.", m),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "Argument mode \"{}\" is not valid.",
+ m
+ ))
+ .into());
}
Some(m) => m,
};
@@ -63,11 +61,9 @@ impl InputArgument {
pub fn set_default(&mut self, default: PhpMixed) -> anyhow::Result<()> {
if self.is_required() && !matches!(default, PhpMixed::Null) {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: "Cannot set a default value except for InputArgument::OPTIONAL mode."
- .to_string(),
- code: 0,
- })
+ return Err(LogicException::new(
+ "Cannot set a default value except for InputArgument::OPTIONAL mode.".to_string(),
+ )
.into());
}
@@ -76,11 +72,9 @@ impl InputArgument {
PhpMixed::Null => PhpMixed::List(vec![]),
PhpMixed::List(_) => default,
_ => {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: "A default value for an array argument must be an array."
- .to_string(),
- code: 0,
- })
+ return Err(LogicException::new(
+ "A default value for an array argument must be an array.".to_string(),
+ )
.into());
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs
index eabb7003..bd32a8f9 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs
@@ -110,39 +110,30 @@ impl InputDefinition {
let argument = std::rc::Rc::new(argument);
if self.arguments.contains_key(argument.get_name()) {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: format!(
- "An argument with name \"{}\" already exists.",
- argument.get_name(),
- ),
- code: 0,
- })
+ return Err(LogicException::new(format!(
+ "An argument with name \"{}\" already exists.",
+ argument.get_name(),
+ ))
.into());
}
if let Some(last_array_argument) = &self.last_array_argument {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: format!(
- "Cannot add a required argument \"{}\" after an array argument \"{}\".",
- argument.get_name(),
- last_array_argument.get_name(),
- ),
- code: 0,
- })
+ return Err(LogicException::new(format!(
+ "Cannot add a required argument \"{}\" after an array argument \"{}\".",
+ argument.get_name(),
+ last_array_argument.get_name(),
+ ))
.into());
}
if argument.is_required()
&& let Some(last_optional_argument) = &self.last_optional_argument
{
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: format!(
- "Cannot add a required argument \"{}\" after an optional one \"{}\".",
- argument.get_name(),
- last_optional_argument.get_name(),
- ),
- code: 0,
- })
+ return Err(LogicException::new(format!(
+ "Cannot add a required argument \"{}\" after an optional one \"{}\".",
+ argument.get_name(),
+ last_optional_argument.get_name(),
+ ))
.into());
}
@@ -165,13 +156,11 @@ impl InputDefinition {
/// Returns an InputArgument by name or by position.
pub fn get_argument(&self, name: &PhpMixed) -> anyhow::Result<std::rc::Rc<InputArgument>> {
if !self.has_argument(name) {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"{}\" argument does not exist.", name.clone()),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "The \"{}\" argument does not exist.",
+ name.clone()
+ ))
+ .into());
}
match name {
@@ -260,17 +249,17 @@ impl InputDefinition {
if let Some(existing) = self.options.get(option.get_name())
&& !option.equals(existing)
{
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: format!("An option named \"{}\" already exists.", option.get_name()),
- code: 0,
- })
+ return Err(LogicException::new(format!(
+ "An option named \"{}\" already exists.",
+ option.get_name()
+ ))
.into());
}
if self.negations.contains_key(option.get_name()) {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: format!("An option named \"{}\" already exists.", option.get_name()),
- code: 0,
- })
+ return Err(LogicException::new(format!(
+ "An option named \"{}\" already exists.",
+ option.get_name()
+ ))
.into());
}
@@ -279,13 +268,10 @@ impl InputDefinition {
if let Some(existing_name) = self.shortcuts.get(&shortcut)
&& !option.equals(&self.options[existing_name])
{
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: format!(
- "An option with shortcut \"{}\" already exists.",
- shortcut.clone(),
- ),
- code: 0,
- })
+ return Err(LogicException::new(format!(
+ "An option with shortcut \"{}\" already exists.",
+ shortcut.clone(),
+ ))
.into());
}
}
@@ -303,10 +289,10 @@ impl InputDefinition {
if option.is_negatable() {
let negated_name = format!("no-{}", option.get_name());
if self.options.contains_key(&negated_name) {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: format!("An option named \"{}\" already exists.", negated_name),
- code: 0,
- })
+ return Err(LogicException::new(format!(
+ "An option named \"{}\" already exists.",
+ negated_name
+ ))
.into());
}
self.negations
@@ -319,13 +305,11 @@ impl InputDefinition {
/// Returns an InputOption by name.
pub fn get_option(&self, name: &str) -> anyhow::Result<std::rc::Rc<InputOption>> {
if !self.has_option(name) {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"--{}\" option does not exist.", name),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "The \"--{}\" option does not exist.",
+ name
+ ))
+ .into());
}
Ok(std::rc::Rc::clone(&self.options[name]))
@@ -374,13 +358,11 @@ impl InputDefinition {
/// Returns the InputOption name given a shortcut.
pub fn shortcut_to_name(&self, shortcut: &str) -> anyhow::Result<String> {
match self.shortcuts.get(shortcut) {
- None => Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"-{}\" option does not exist.", shortcut),
- code: 0,
- })
- .into(),
- ),
+ None => Err(InvalidArgumentException::new(format!(
+ "The \"-{}\" option does not exist.",
+ shortcut
+ ))
+ .into()),
Some(name) => Ok(name.clone()),
}
}
@@ -388,13 +370,11 @@ impl InputDefinition {
/// Returns the InputOption name given a negation.
pub fn negation_to_name(&self, negation: &str) -> anyhow::Result<String> {
match self.negations.get(negation) {
- None => Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("The \"--{}\" option does not exist.", negation),
- code: 0,
- })
- .into(),
- ),
+ None => Err(InvalidArgumentException::new(format!(
+ "The \"--{}\" option does not exist.",
+ negation
+ ))
+ .into()),
Some(name) => Ok(name.clone()),
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs
index 3f8fdeaf..79eff582 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs
@@ -34,13 +34,10 @@ impl InputOption {
};
if name.is_empty() {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: "An option name cannot be empty.".to_string(),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(
+ "An option name cannot be empty.".to_string(),
+ )
+ .into());
}
let shortcut = match shortcut {
@@ -69,13 +66,11 @@ impl InputOption {
let mode = match mode {
None => Self::VALUE_NONE,
Some(m) if !(1..(Self::VALUE_NEGATABLE << 1)).contains(&m) => {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!("Option mode \"{}\" is not valid.", m),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "Option mode \"{}\" is not valid.",
+ m
+ ))
+ .into());
}
Some(m) => m,
};
@@ -89,17 +84,11 @@ impl InputOption {
};
if option.is_array() && !option.accept_value() {
- return Err(InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: "Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.".to_string(),
- code: 0,
- })
+ return Err(InvalidArgumentException::new("Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.".to_string())
.into());
}
if option.is_negatable() && option.accept_value() {
- return Err(InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: "Impossible to have an option mode VALUE_NEGATABLE if the option also accepts a value.".to_string(),
- code: 0,
- })
+ return Err(InvalidArgumentException::new("Impossible to have an option mode VALUE_NEGATABLE if the option also accepts a value.".to_string())
.into());
}
@@ -115,13 +104,10 @@ impl InputOption {
shirabe_php_shim::array_filter(&parts, |s: &String| !s.is_empty());
let result = shirabe_php_shim::implode("|", &filtered);
if result.is_empty() {
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: "An option shortcut cannot be empty.".to_string(),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(
+ "An option shortcut cannot be empty.".to_string(),
+ )
+ .into());
}
Ok(Some(result))
}
@@ -157,11 +143,9 @@ impl InputOption {
pub fn set_default(&mut self, default: PhpMixed) -> anyhow::Result<()> {
if Self::VALUE_NONE == (Self::VALUE_NONE & self.mode) && !matches!(default, PhpMixed::Null)
{
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: "Cannot set a default value when using InputOption::VALUE_NONE mode."
- .to_string(),
- code: 0,
- })
+ return Err(LogicException::new(
+ "Cannot set a default value when using InputOption::VALUE_NONE mode.".to_string(),
+ )
.into());
}
@@ -171,11 +155,9 @@ impl InputOption {
// PHP `is_array()` accepts both list-style and associative arrays.
PhpMixed::List(_) | PhpMixed::Array(_) => default,
_ => {
- return Err(LogicException(shirabe_php_shim::LogicException {
- message: "A default value for an array option must be an array."
- .to_string(),
- code: 0,
- })
+ return Err(LogicException::new(
+ "A default value for an array option must be an array.".to_string(),
+ )
.into());
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs
index 3b3c3207..0ca8c975 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs
@@ -127,16 +127,11 @@ impl StringInput {
shirabe_php_shim::strlen(m[&CaptureKey::ByIndex(0)].as_deref().unwrap_or(""));
} else {
// should never happen
- return Err(
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "Unable to parse input near \"... {} ...\".",
- shirabe_php_shim::substr(input, cursor, Some(10)),
- ),
- code: 0,
- })
- .into(),
- );
+ return Err(InvalidArgumentException::new(format!(
+ "Unable to parse input near \"... {} ...\".",
+ shirabe_php_shim::substr(input, cursor, Some(10)),
+ ))
+ .into());
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs b/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs
index 4d8eb921..9140dbc8 100644
--- a/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/output/stream_output.rs
@@ -37,12 +37,8 @@ impl StreamOutput {
let verbosity = verbosity.unwrap_or(VERBOSITY_NORMAL);
if shirabe_php_shim::get_resource_type(&stream) != "stream" {
- return Ok(Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: "The StreamOutput class needs a stream as its first argument."
- .to_string(),
- code: 0,
- },
+ return Ok(Err(InvalidArgumentException::new(
+ "The StreamOutput class needs a stream as its first argument.".to_string(),
)));
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs b/crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs
index b42f2a4e..4eb91b41 100644
--- a/crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs
@@ -21,16 +21,10 @@ impl TrimmedBufferOutput {
formatter: Option<std::rc::Rc<std::cell::RefCell<dyn OutputFormatterInterface>>>,
) -> Result<Self, InvalidArgumentException> {
if max_length <= 0 {
- return Err(InvalidArgumentException(
- shirabe_php_shim::InvalidArgumentException {
- message: format!(
- "\"{}()\" expects a strictly positive maxLength. Got {}.",
- "Symfony\\Component\\Console\\Output\\TrimmedBufferOutput::__construct",
- max_length,
- ),
- code: 0,
- },
- ));
+ return Err(InvalidArgumentException::new(format!(
+ "\"{}()\" expects a strictly positive maxLength. Got {}.",
+ "Symfony\\Component\\Console\\Output\\TrimmedBufferOutput::__construct", max_length,
+ )));
}
Ok(Self {
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(),
));
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
index b62c2565..e0994e99 100644
--- a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
@@ -469,12 +469,7 @@ impl SymfonyStyle {
) -> Option<Box<dyn Fn(Option<PhpMixed>) -> Result<PhpMixed, InvalidArgumentException>>> {
validator.map(|validator| {
Box::new(move |value: Option<PhpMixed>| {
- validator(value).map_err(|e| {
- InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: e.to_string(),
- code: 0,
- })
- })
+ validator(value).map_err(|e| InvalidArgumentException::new(e.to_string()))
})
as Box<dyn Fn(Option<PhpMixed>) -> Result<PhpMixed, InvalidArgumentException>>
})