aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-22 01:43:34 +0900
committernsfisis <nsfisis@gmail.com>2026-05-22 01:44:05 +0900
commit6739da8a8e271a82d1bf8ca79bba58640ae6e743 (patch)
treece397b02662cf3c101cb36545b0a6c94ddc21826
parent0b06f54103490e3ce5658e82bbc0119633e26cd8 (diff)
downloadphp-shirabe-6739da8a8e271a82d1bf8ca79bba58640ae6e743.tar.gz
php-shirabe-6739da8a8e271a82d1bf8ca79bba58640ae6e743.tar.zst
php-shirabe-6739da8a8e271a82d1bf8ca79bba58640ae6e743.zip
refactor(php-shim): remove unnecessary methods
-rw-r--r--crates/shirabe-php-shim/src/lib.rs26
-rw-r--r--crates/shirabe/src/command/archive_command.rs13
-rw-r--r--crates/shirabe/src/command/audit_command.rs2
-rw-r--r--crates/shirabe/src/command/base_config_command.rs2
-rw-r--r--crates/shirabe/src/command/dump_autoload_command.rs2
-rw-r--r--crates/shirabe/src/command/exec_command.rs4
-rw-r--r--crates/shirabe/src/command/install_command.rs2
-rw-r--r--crates/shirabe/src/command/reinstall_command.rs2
-rw-r--r--crates/shirabe/src/command/remove_command.rs6
-rw-r--r--crates/shirabe/src/command/run_script_command.rs6
-rw-r--r--crates/shirabe/src/command/search_command.rs7
-rw-r--r--crates/shirabe/src/command/update_command.rs2
-rw-r--r--crates/shirabe/src/command/validate_command.rs2
-rw-r--r--crates/shirabe/src/json/json_manipulator.rs14
-rw-r--r--crates/shirabe/src/util/filesystem.rs10
-rw-r--r--crates/shirabe/src/util/url.rs4
16 files changed, 38 insertions, 66 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs
index f01f16c..b265111 100644
--- a/crates/shirabe-php-shim/src/lib.rs
+++ b/crates/shirabe-php-shim/src/lib.rs
@@ -77,27 +77,10 @@ impl PhpMixed {
}
}
- pub fn as_str(&self) -> Option<&str> {
- self.as_string()
- }
-
pub fn is_null(&self) -> bool {
matches!(self, PhpMixed::Null)
}
- /// Treats PhpMixed::Null as None, everything else as Some.
- pub fn is_none(&self) -> bool {
- self.is_null()
- }
-
- pub fn is_some(&self) -> bool {
- !self.is_null()
- }
-
- pub fn as_string_opt(&self) -> Option<&str> {
- self.as_string()
- }
-
pub fn get(&self, key: &str) -> Option<&PhpMixed> {
self.as_array().and_then(|m| m.get(key).map(|v| v.as_ref()))
}
@@ -122,20 +105,11 @@ impl PhpMixed {
self
}
- pub fn as_ref(&self) -> Option<&PhpMixed> {
- self.as_opt()
- }
-
/// Treats PhpMixed::Null as None and applies the function for chaining.
pub fn and_then<U, F: FnOnce(&PhpMixed) -> Option<U>>(&self, f: F) -> Option<U> {
self.as_opt().and_then(f)
}
- /// Counterpart to `Any::as_any` for trait-object call sites that downcast.
- pub fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
/// Treats `Null` and `Bool(false)` as the falsy case, anything else as Some.
pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<PhpMixed, E> {
match self {
diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs
index c823860..01da89d 100644
--- a/crates/shirabe/src/command/archive_command.rs
+++ b/crates/shirabe/src/command/archive_command.rs
@@ -90,7 +90,7 @@ impl ArchiveCommand {
let format = input
.get_option("format")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string())
.unwrap_or_else(|| {
config
@@ -103,7 +103,7 @@ impl ArchiveCommand {
let dir = input
.get_option("dir")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string())
.unwrap_or_else(|| {
config
@@ -121,18 +121,15 @@ impl ArchiveCommand {
&config,
input
.get_argument("package")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string()),
input
.get_argument("version")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string()),
&format,
&dir,
- input
- .get_option("file")
- .as_string_opt()
- .map(|s| s.to_string()),
+ input.get_option("file").as_string().map(|s| s.to_string()),
input
.get_option("ignore-filters")
.as_bool()
diff --git a/crates/shirabe/src/command/audit_command.rs b/crates/shirabe/src/command/audit_command.rs
index e814821..f4f27e9 100644
--- a/crates/shirabe/src/command/audit_command.rs
+++ b/crates/shirabe/src/command/audit_command.rs
@@ -86,7 +86,7 @@ impl AuditCommand {
let abandoned = input
.get_option("abandoned")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string());
if abandoned.is_some()
&& !in_array(
diff --git a/crates/shirabe/src/command/base_config_command.rs b/crates/shirabe/src/command/base_config_command.rs
index 081120d..2da93dc 100644
--- a/crates/shirabe/src/command/base_config_command.rs
+++ b/crates/shirabe/src/command/base_config_command.rs
@@ -108,7 +108,7 @@ pub trait BaseConfigCommand: BaseCommand {
} else {
input
.get_option("file")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string())
.unwrap_or_else(|| Factory::get_composer_file().unwrap_or_default())
}
diff --git a/crates/shirabe/src/command/dump_autoload_command.rs b/crates/shirabe/src/command/dump_autoload_command.rs
index 588c91e..275e635 100644
--- a/crates/shirabe/src/command/dump_autoload_command.rs
+++ b/crates/shirabe/src/command/dump_autoload_command.rs
@@ -94,7 +94,7 @@ impl DumpAutoloadCommand {
.unwrap_or(false);
let apcu_prefix = input
.get_option("apcu-prefix")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string());
let apcu = apcu_prefix.is_some()
|| input.get_option("apcu").as_bool().unwrap_or(false)
diff --git a/crates/shirabe/src/command/exec_command.rs b/crates/shirabe/src/command/exec_command.rs
index 68e2d0f..23aa103 100644
--- a/crates/shirabe/src/command/exec_command.rs
+++ b/crates/shirabe/src/command/exec_command.rs
@@ -48,7 +48,7 @@ impl ExecCommand {
return Ok(());
}
- if input.get_argument("binary").as_string_opt().is_some()
+ if input.get_argument("binary").as_string().is_some()
|| input.get_option("list").as_bool().unwrap_or(false)
{
return Ok(());
@@ -82,7 +82,7 @@ impl ExecCommand {
let composer = self.require_composer(None, None)?;
if input.get_option("list").as_bool().unwrap_or(false)
- || input.get_argument("binary").as_string_opt().is_none()
+ || input.get_argument("binary").as_string().is_none()
{
let bins = self.get_binaries(true)?;
if bins.is_empty() {
diff --git a/crates/shirabe/src/command/install_command.rs b/crates/shirabe/src/command/install_command.rs
index 632ccb1..a0710dc 100644
--- a/crates/shirabe/src/command/install_command.rs
+++ b/crates/shirabe/src/command/install_command.rs
@@ -140,7 +140,7 @@ impl InstallCommand {
.unwrap_or(false);
let apcu_prefix = input
.get_option("apcu-autoloader-prefix")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string());
let apcu = apcu_prefix.is_some()
|| input
diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs
index 8bb4643..d66a830 100644
--- a/crates/shirabe/src/command/reinstall_command.rs
+++ b/crates/shirabe/src/command/reinstall_command.rs
@@ -255,7 +255,7 @@ impl ReinstallCommand {
.unwrap_or(false);
let apcu_prefix = input
.get_option("apcu-autoloader-prefix")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string());
let apcu = apcu_prefix.is_some()
|| input
diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs
index ab322f9..49b21dc 100644
--- a/crates/shirabe/src/command/remove_command.rs
+++ b/crates/shirabe/src/command/remove_command.rs
@@ -477,7 +477,7 @@ impl RemoveCommand {
let allow_plugins = composer.get_config().borrow_mut().get("allow-plugins");
let removed_plugins: Vec<String> =
- if let Some(allow_map) = allow_plugins.as_ref().and_then(|v| v.as_array()) {
+ if let Some(allow_map) = allow_plugins.as_opt().and_then(|v| v.as_array()) {
packages
.iter()
.filter(|p| allow_map.contains_key(p.as_str()))
@@ -488,11 +488,11 @@ impl RemoveCommand {
};
if !dry_run
- && allow_plugins.as_ref().and_then(|v| v.as_array()).is_some()
+ && allow_plugins.as_opt().and_then(|v| v.as_array()).is_some()
&& !removed_plugins.is_empty()
{
let allow_map_len = allow_plugins
- .as_ref()
+ .as_opt()
.and_then(|v| v.as_array())
.map(|m| m.len())
.unwrap_or(0);
diff --git a/crates/shirabe/src/command/run_script_command.rs b/crates/shirabe/src/command/run_script_command.rs
index 436d906..e58ad24 100644
--- a/crates/shirabe/src/command/run_script_command.rs
+++ b/crates/shirabe/src/command/run_script_command.rs
@@ -122,7 +122,7 @@ impl RunScriptCommand {
return Ok(());
}
- if input.get_argument("script").as_string_opt().is_some()
+ if input.get_argument("script").as_string().is_some()
|| input.get_option("list").as_bool().unwrap_or(false)
{
return Ok(());
@@ -160,7 +160,7 @@ impl RunScriptCommand {
return self.list_scripts(output);
}
- let script = match input.get_argument("script").as_string_opt() {
+ let script = match input.get_argument("script").as_string() {
None => {
return Err(RuntimeException {
message: "Missing required argument \"script\"".to_string(),
@@ -209,7 +209,7 @@ impl RunScriptCommand {
})
.unwrap_or_default();
- if let Some(timeout_val) = input.get_option("timeout").as_string_opt() {
+ if let Some(timeout_val) = input.get_option("timeout").as_string() {
let timeout_str = timeout_val.to_string();
if !timeout_str.chars().all(|c| c.is_ascii_digit()) {
return Err(RuntimeException {
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs
index fb6b047..9375ec7 100644
--- a/crates/shirabe/src/command/search_command.rs
+++ b/crates/shirabe/src/command/search_command.rs
@@ -51,7 +51,7 @@ impl SearchCommand {
let format = input
.get_option("format")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string())
.unwrap_or_else(|| "text".to_string());
if !in_array(
@@ -114,10 +114,7 @@ impl SearchCommand {
mode = repository_interface::SEARCH_VENDOR;
}
- let r#type = input
- .get_option("type")
- .as_string_opt()
- .map(|s| s.to_string());
+ let r#type = input.get_option("type").as_string().map(|s| s.to_string());
let tokens_arg = input.get_argument("tokens");
let token_strings: Vec<String> = tokens_arg
diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs
index b96793d..c4ae890 100644
--- a/crates/shirabe/src/command/update_command.rs
+++ b/crates/shirabe/src/command/update_command.rs
@@ -341,7 +341,7 @@ impl UpdateCommand {
.unwrap_or(false);
let apcu_prefix: Option<String> = input
.get_option("apcu-autoloader-prefix")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string());
let apcu = apcu_prefix.is_some()
|| input
diff --git a/crates/shirabe/src/command/validate_command.rs b/crates/shirabe/src/command/validate_command.rs
index f57c21c..60514a1 100644
--- a/crates/shirabe/src/command/validate_command.rs
+++ b/crates/shirabe/src/command/validate_command.rs
@@ -114,7 +114,7 @@ impl ValidateCommand {
) -> Result<i64> {
let file = input
.get_argument("file")
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string())
.map(Ok)
.unwrap_or_else(Factory::get_composer_file)?;
diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs
index c9ca7f7..e5510d3 100644
--- a/crates/shirabe/src/json/json_manipulator.rs
+++ b/crates/shirabe/src/json/json_manipulator.rs
@@ -269,7 +269,7 @@ impl JsonManipulator {
.and_then(|o| o.to_array().get("repositories").cloned());
let is_std_class = repositories_value
.as_ref()
- .map(|v| v.as_any().is::<StdClass>())
+ .map(|v| (&**v as &dyn std::any::Any).is::<StdClass>())
.unwrap_or(false);
if is_std_class {
@@ -290,7 +290,7 @@ impl JsonManipulator {
// re-add in order
for (repository_name, repository) in &repos_arr {
- let is_obj = repository.as_any().is::<StdClass>();
+ let is_obj = (&**repository as &dyn std::any::Any).is::<StdClass>();
if !is_obj {
let mut m: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
m.insert(repository_name.clone(), repository.clone());
@@ -515,7 +515,7 @@ impl JsonManipulator {
.and_then(|o| o.to_array().get("repositories").cloned());
let is_assoc = repositories_value
.as_ref()
- .map(|v| v.as_any().is::<StdClass>())
+ .map(|v| (&**v as &dyn std::any::Any).is::<StdClass>())
.unwrap_or(false);
let repos: IndexMap<String, Box<PhpMixed>> = repositories_value
@@ -1689,7 +1689,9 @@ impl JsonManipulator {
pub fn format(&self, data: &PhpMixed, depth: i64, was_object: bool) -> anyhow::Result<String> {
let mut data = data.clone();
let mut was_object = was_object;
- if data.as_any().is::<StdClass>() || data.as_any().is::<ArrayObject>() {
+ if (&data as &dyn std::any::Any).is::<StdClass>()
+ || (&data as &dyn std::any::Any).is::<ArrayObject>()
+ {
// PHP: (array) $data — coerce to array
if let Some(obj) = data.as_object() {
data = PhpMixed::Array(obj.to_array());
@@ -1761,7 +1763,9 @@ impl ManipulatorFormatter {
fn format(&self, data: &PhpMixed, depth: i64, was_object: bool) -> anyhow::Result<String> {
let mut data = data.clone();
let mut was_object = was_object;
- if data.as_any().is::<StdClass>() || data.as_any().is::<ArrayObject>() {
+ if (&data as &dyn std::any::Any).is::<StdClass>()
+ || (&data as &dyn std::any::Any).is::<ArrayObject>()
+ {
if let Some(obj) = data.as_object() {
data = PhpMixed::Array(obj.to_array());
}
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index a51b0f3..96316e9 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -419,7 +419,7 @@ impl Filesystem {
if str_contains(&e.message, "Bad address") {
let source_handle = fopen(source, "r");
let target_handle = fopen(&target, "w");
- if source_handle.is_none() || target_handle.is_none() {
+ if source_handle.is_null() || target_handle.is_null() {
return Err(e.into());
}
while !feof(source_handle.clone()) {
@@ -1035,14 +1035,14 @@ impl Filesystem {
pub fn safe_copy(&self, source: &str, target: &str) -> anyhow::Result<()> {
if !file_exists(target) || !file_exists(source) || !self.files_are_equal(source, target) {
let source_handle = fopen(source, "r");
- if source_handle.is_none() {
+ if source_handle.is_null() {
return Err(anyhow::anyhow!(
"Could not open \"{}\" for reading.",
source
));
}
let target_handle = fopen(target, "w+");
- if target_handle.is_none() {
+ if target_handle.is_null() {
return Err(anyhow::anyhow!(
"Could not open \"{}\" for writing.",
target
@@ -1070,11 +1070,11 @@ impl Filesystem {
// Check if content is different
let a_handle = fopen(a, "rb");
- if a_handle.is_none() {
+ if a_handle.is_null() {
return false;
}
let b_handle = fopen(b, "rb");
- if b_handle.is_none() {
+ if b_handle.is_null() {
return false;
}
diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs
index a6736aa..8bcd73e 100644
--- a/crates/shirabe/src/util/url.rs
+++ b/crates/shirabe/src/util/url.rs
@@ -11,7 +11,7 @@ pub struct Url;
impl Url {
pub fn update_dist_reference(config: &Config, mut url: String, r#ref: &str) -> String {
let host = parse_url(&url, PHP_URL_HOST)
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string())
.unwrap_or_default();
@@ -128,7 +128,7 @@ impl Url {
}
let mut origin = parse_url(url, PHP_URL_HOST)
- .as_string_opt()
+ .as_string()
.map(|s| s.to_string())
.unwrap_or_default();
if let Some(port) = parse_url(url, PHP_URL_PORT).as_int() {