diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-11 23:28:40 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-11 23:28:40 +0900 |
| commit | 38621c67917fd015f884ea04517791cdc5058c6d (patch) | |
| tree | 03f466e2db22a3bc45e20e4f9694eb371a59b0e1 | |
| parent | 73ab00d3108933c952844b3820f44230c8203807 (diff) | |
| download | php-shirabe-38621c67917fd015f884ea04517791cdc5058c6d.tar.gz php-shirabe-38621c67917fd015f884ea04517791cdc5058c6d.tar.zst php-shirabe-38621c67917fd015f884ea04517791cdc5058c6d.zip | |
chore(php-shim): drop the substring predicate ports
str_contains(), str_starts_with() and str_ends_with() were thin wrappers
over the str methods of the same semantics. Call sites now use
contains()/starts_with()/ends_with() directly.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
23 files changed, 88 insertions, 110 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs index 0042a0a1..2207416b 100644 --- a/crates/shirabe-class-map-generator/src/class_map_generator.rs +++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs @@ -8,7 +8,7 @@ use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PATHINFO_EXTENSION, RuntimeException, explode, getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_quote, realpath, str_replace, - str_starts_with, stream_get_wrappers, strlen, strpos, strrpos, strtr, substr, + stream_get_wrappers, strlen, strpos, strrpos, strtr, substr, }; use shirabe_symfony_finder::Finder; use std::path::PathBuf; @@ -254,7 +254,7 @@ impl ClassMapGenerator { let sub_path: String; if namespace_type == "psr-0" { - if !base_namespace.is_empty() && !str_starts_with(&class, base_namespace) { + if !base_namespace.is_empty() && !class.starts_with(base_namespace) { rejected_classes.push(class); continue; } diff --git a/crates/shirabe-php-shim/src/string.rs b/crates/shirabe-php-shim/src/string.rs index 8cab6eca..e53fc02c 100644 --- a/crates/shirabe-php-shim/src/string.rs +++ b/crates/shirabe-php-shim/src/string.rs @@ -14,18 +14,6 @@ pub fn str_replace(search: &str, replace: &str, subject: &str) -> String { subject.replace(search, replace) } -pub fn str_contains(haystack: &str, needle: &str) -> bool { - haystack.contains(needle) -} - -pub fn str_starts_with(haystack: &str, needle: &str) -> bool { - haystack.starts_with(needle) -} - -pub fn str_ends_with(haystack: &str, needle: &str) -> bool { - haystack.ends_with(needle) -} - pub fn substr_count(haystack: &str, needle: &str) -> i64 { if needle.is_empty() { panic!("substr_count(): Argument #2 ($needle) cannot be empty"); diff --git a/crates/shirabe-symfony-console/src/completion/completion_input.rs b/crates/shirabe-symfony-console/src/completion/completion_input.rs index aef23d4a..a0adff6c 100644 --- a/crates/shirabe-symfony-console/src/completion/completion_input.rs +++ b/crates/shirabe-symfony-console/src/completion/completion_input.rs @@ -84,7 +84,7 @@ impl CompletionInput { self.completion_name = Some(option.get_name().to_string()); self.completion_value = if !option_value.is_empty() { option_value - } else if !shirabe_php_shim::str_starts_with(&option_token, "--") { + } else if !option_token.starts_with("--") { shirabe_php_shim::substr(&option_token, 2, None) } else { String::new() diff --git a/crates/shirabe-symfony-console/src/formatter/output_formatter.rs b/crates/shirabe-symfony-console/src/formatter/output_formatter.rs index 649af71d..245707d9 100644 --- a/crates/shirabe-symfony-console/src/formatter/output_formatter.rs +++ b/crates/shirabe-symfony-console/src/formatter/output_formatter.rs @@ -34,7 +34,7 @@ impl OutputFormatter { /// Escapes trailing "\" in given text. pub fn escape_trailing_backslash(text: &str) -> String { let mut text = text.to_string(); - if shirabe_php_shim::str_ends_with(&text, "\\") { + if text.ends_with('\\') { let len = shirabe_php_shim::strlen(&text); text = shirabe_php_shim::rtrim(&text, Some("\\")); text = shirabe_php_shim::str_replace("\0", "", &text); diff --git a/crates/shirabe-symfony-console/src/helper/question_helper.rs b/crates/shirabe-symfony-console/src/helper/question_helper.rs index 662edf40..c051fff2 100644 --- a/crates/shirabe-symfony-console/src/helper/question_helper.rs +++ b/crates/shirabe-symfony-console/src/helper/question_helper.rs @@ -557,10 +557,7 @@ impl QuestionHelper { .into_iter() .filter(|m| { ret_for_filter.is_empty() - || shirabe_php_shim::str_starts_with( - &m.to_string(), - &ret_for_filter, - ) + || m.to_string().starts_with(&ret_for_filter) }) .collect(); ofs = -1; @@ -616,7 +613,7 @@ impl QuestionHelper { for value in autocomplete(&ret) { // If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle) - if shirabe_php_shim::str_starts_with(&value.to_string(), &temp_ret) { + if value.to_string().starts_with(&temp_ret) { if (num_matches as usize) < matches.len() { matches[num_matches as usize] = value; } else { @@ -660,7 +657,7 @@ impl QuestionHelper { fn most_recently_entered_value(&self, entered: &str) -> String { // Determine the most recent value that the user entered - if !shirabe_php_shim::str_contains(entered, ",") { + if !entered.contains(',') { return entered.to_string(); } diff --git a/crates/shirabe-symfony-console/src/helper/table.rs b/crates/shirabe-symfony-console/src/helper/table.rs index 177e23c0..06743dbf 100644 --- a/crates/shirabe-symfony-console/src/helper/table.rs +++ b/crates/shirabe-symfony-console/src/helper/table.rs @@ -745,7 +745,7 @@ impl Table { if shirabe_php_shim::strstr(&cell_str, "\n").is_none() { continue; } - let eol = if shirabe_php_shim::str_contains(&cell_str, "\r\n") { + let eol = if cell_str.contains("\r\n") { "\r\n" } else { "\n" @@ -846,7 +846,7 @@ impl Table { let cell_str = cell.to_php_string(); let mut lines = vec![cell.clone()]; if shirabe_php_shim::strstr(&cell_str, "\n").is_some() { - let eol = if shirabe_php_shim::str_contains(&cell_str, "\r\n") { + let eol = if cell_str.contains("\r\n") { "\r\n" } else { "\n" diff --git a/crates/shirabe-symfony-console/src/input/argv_input.rs b/crates/shirabe-symfony-console/src/input/argv_input.rs index cbd0f6d2..200c7384 100644 --- a/crates/shirabe-symfony-console/src/input/argv_input.rs +++ b/crates/shirabe-symfony-console/src/input/argv_input.rs @@ -116,7 +116,7 @@ impl ArgvInput { self.parse_argument(token)?; } else if parse_options && token == "--" { return Ok(false); - } else if parse_options && shirabe_php_shim::str_starts_with(token, "--") { + } else if parse_options && token.starts_with("--") { self.parse_long_option(token)?; } else if parse_options && token.as_bytes().first() == Some(&b'-') && token != "-" { self.parse_short_option(token)?; @@ -405,7 +405,7 @@ impl ArgvInput { let mut is_option = false; for (i, token) in self.tokens.iter().enumerate() { if !token.is_empty() && token.as_bytes()[0] == b'-' { - if shirabe_php_shim::str_contains(token, "=") || self.tokens.get(i + 1).is_none() { + if token.contains('=') || self.tokens.get(i + 1).is_none() { continue; } @@ -458,14 +458,12 @@ impl ArgvInput { // Options with values: // For long options, test for '--option=' at beginning // For short options, test for '-o' at beginning - let leading = if shirabe_php_shim::str_starts_with(value, "--") { + let leading = if value.starts_with("--") { format!("{}=", value) } else { value.clone() }; - if token == value - || (!leading.is_empty() && shirabe_php_shim::str_starts_with(token, &leading)) - { + if token == value || (!leading.is_empty() && token.starts_with(&leading)) { return true; } } @@ -499,12 +497,12 @@ impl ArgvInput { // Options with values: // For long options, test for '--option=' at beginning // For short options, test for '-o' at beginning - let leading = if shirabe_php_shim::str_starts_with(value, "--") { + let leading = if value.starts_with("--") { format!("{}=", value) } else { value.clone() }; - if !leading.is_empty() && shirabe_php_shim::str_starts_with(&token, &leading) { + if !leading.is_empty() && token.starts_with(&leading) { return PhpMixed::String(shirabe_php_shim::substr( &token, shirabe_php_shim::strlen(&leading), diff --git a/crates/shirabe-symfony-console/src/input/array_input.rs b/crates/shirabe-symfony-console/src/input/array_input.rs index d93501c7..e19381a9 100644 --- a/crates/shirabe-symfony-console/src/input/array_input.rs +++ b/crates/shirabe-symfony-console/src/input/array_input.rs @@ -139,9 +139,9 @@ impl ArrayInput { if key == "--" { return Ok(()); } - if shirabe_php_shim::str_starts_with(&key, "--") { + if key.starts_with("--") { self.add_long_option(&shirabe_php_shim::substr(&key, 2, None), value)?; - } else if shirabe_php_shim::str_starts_with(&key, "-") { + } else if key.starts_with("-") { self.add_short_option(&shirabe_php_shim::substr(&key, 1, None), value)?; } else { self.add_argument(&PhpMixed::String(key), value)?; diff --git a/crates/shirabe-symfony-console/src/style/symfony_style.rs b/crates/shirabe-symfony-console/src/style/symfony_style.rs index ead056d5..881d87e0 100644 --- a/crates/shirabe-symfony-console/src/style/symfony_style.rs +++ b/crates/shirabe-symfony-console/src/style/symfony_style.rs @@ -312,7 +312,7 @@ impl SymfonyStyle { fn auto_prepend_text(&mut self) { let fetched = self.buffered_output.fetch(); // Prepend new line if last char isn't EOL: - if !shirabe_php_shim::str_ends_with(&fetched, "\n") { + if !fetched.ends_with('\n') { self.new_line(1); } } diff --git a/crates/shirabe/src/advisory/auditor.rs b/crates/shirabe/src/advisory/auditor.rs index 3c00d09e..40a8d53c 100644 --- a/crates/shirabe/src/advisory/auditor.rs +++ b/crates/shirabe/src/advisory/auditor.rs @@ -15,7 +15,7 @@ use indexmap::IndexMap; use shirabe_pcre::Preg; use shirabe_php_shim::{ DATE_ATOM, InvalidArgumentException, PhpMixed, array_all, array_any, array_key_exists, - array_keys, array_reduce, get_class, str_starts_with, + array_keys, array_reduce, get_class, }; use shirabe_symfony_console::formatter::OutputFormatter; @@ -266,7 +266,7 @@ impl Auditor { let ignored_ids = array_keys(ignore_list); - array_any(&ignored_ids, |id: &String| !str_starts_with(id, "PKSA-")) + array_any(&ignored_ids, |id: &String| !id.starts_with("PKSA-")) } pub fn filter_abandoned_packages( @@ -656,7 +656,7 @@ impl Auditor { fn get_advisory_id(&self, advisory: &SecurityAdvisory) -> String { let advisory_id = advisory.advisory_id(); - if str_starts_with(advisory_id, "PKSA-") { + if advisory_id.starts_with("PKSA-") { return format!( "<href=https://packagist.org/security-advisories/{}>{}</>", advisory_id, advisory_id diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs index 27a3660e..10f76536 100644 --- a/crates/shirabe/src/autoload/autoload_generator.rs +++ b/crates/shirabe/src/autoload/autoload_generator.rs @@ -28,8 +28,8 @@ use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, array_keys, array_map, array_merge_map, array_merge_recursive, array_shift, array_slice_strs, array_unique, bin2hex, explode, file_exists, file_get_contents, hash, implode, is_array, ksort, ltrim, php_regex, preg_quote, - random_bytes, realpath, str_contains, str_replace, str_starts_with, strlen, strpos, strtr, - substr, substr_count, trim, unlink, var_export, + random_bytes, realpath, str_replace, strlen, strpos, strtr, substr, substr_count, trim, unlink, + var_export, }; use shirabe_semver::constraint::Bound; use shirabe_symfony_console::formatter::OutputFormatter; @@ -456,14 +456,13 @@ return array( } // if the vendor dir is contained within a psr-0/psr-4 dir being scanned we exclude it - let exclusion_regex = - if str_contains(&vendor_path, &format!("{}/", dir_str)) { - let mut combined = excluded.clone(); - combined.push(format!("{}/", vendor_path)); - self.build_exclusion_regex(&dir_str, combined) - } else { - self.build_exclusion_regex(&dir_str, excluded.clone()) - }; + let exclusion_regex = if vendor_path.contains(&format!("{}/", dir_str)) { + let mut combined = excluded.clone(); + combined.push(format!("{}/", vendor_path)); + self.build_exclusion_regex(&dir_str, combined) + } else { + self.build_exclusion_regex(&dir_str, excluded.clone()) + }; class_map_generator.scan_paths( &dir_str, @@ -757,11 +756,11 @@ return array( pattern, ); // if the pattern is not a subset or superset of $dir, it is unrelated and we skip it - let unrelated = (!str_starts_with(&pattern_processed, &dir_match) - && !str_starts_with(&dir_match, &pattern_processed)) + let unrelated = (!pattern_processed.starts_with(&dir_match) + && !dir_match.starts_with(&pattern_processed)) && (!is_symlink - || (!str_starts_with(&pattern_processed, &dir_match_normalized) - && !str_starts_with(&dir_match_normalized, &pattern_processed))); + || (!pattern_processed.starts_with(&dir_match_normalized) + && !dir_match_normalized.starts_with(&pattern_processed))); if !unrelated { new_excluded.push(pattern.clone()); } @@ -1763,7 +1762,7 @@ class ComposerStaticInit{} for (prop, value) in loader.as_array_iter() { if !is_array(&value) || value.as_array().map_or(0, |a| a.len()) == 0 - || !str_starts_with(&prop, prefix) + || !prop.starts_with(prefix) { continue; } diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index ca71c0e5..dc5d7399 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -38,8 +38,8 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ AnyThrowable, CmpOp, InvalidArgumentException, PHP_EOL, PhpClass as _, PhpMixed, disk_free_space, file_exists, filter_var_boolean, hash, impl_php_class, implode, is_array, - is_string, php_regex, rtrim, str_contains, str_replace, str_starts_with, strpos, strstr, - strstr3, strtolower, trim, version_compare, + is_string, php_regex, rtrim, str_replace, strpos, strstr, strstr3, strtolower, trim, + version_compare, }; use shirabe_symfony_console::command::Command; use shirabe_symfony_console::input::InputInterface; @@ -234,8 +234,7 @@ impl DiagnoseCommand { let mut result_list: Vec<PhpMixed> = vec![]; let mut tls_warning: Option<String> = None; - if str_starts_with(url, "https://") - && config.borrow().get("disable-tls").as_bool() == Some(true) + if url.starts_with("https://") && config.borrow().get("disable-tls").as_bool() == Some(true) { tls_warning = Some("<warning>Composer is configured to disable SSL/TLS protection. This will leave remote HTTPS requests vulnerable to Man-In-The-Middle attacks.</warning>".to_string()); } @@ -875,11 +874,11 @@ impl DiagnoseCommand { .unwrap_or_default(); let configure = configure.as_str(); - if str_contains(configure, "--enable-sigchild") { + if configure.contains("--enable-sigchild") { warnings.insert("sigchild".to_string(), PhpMixed::Bool(true)); } - if str_contains(configure, "--with-curlwrappers") { + if configure.contains("--with-curlwrappers") { warnings.insert("curlwrappers".to_string(), PhpMixed::Bool(true)); } } @@ -1228,7 +1227,10 @@ impl Command for DiagnoseCommand { .unwrap(); let mut php_version = php_pkg.get_pretty_version(); if let Some(cp) = php_pkg.as_complete() - && str_contains(&cp.get_description().unwrap_or_default(), "overridden") + && cp + .get_description() + .unwrap_or_default() + .contains("overridden") { php_version = format!( "{} - {}", @@ -1361,10 +1363,10 @@ impl Command for DiagnoseCommand { // We surface the same internal call by directly invoking the equivalent method. // TODO(plugin): support reflection-based access if plugin code requires it. let url = composer_repo.get_packages_json_url(); - if !str_starts_with(&url, "http") { + if !url.starts_with("http") { continue; } - if str_starts_with(&url, "https://repo.packagist.org") { + if url.starts_with("https://repo.packagist.org") { continue; } io.write_no_newline(&format!( diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 197ddfbd..b18eaa02 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -62,8 +62,8 @@ use shirabe_php_shim::{ disk_free_space, extension_loaded, file_exists, file_get_contents, file_put_contents, function_exists, getcwd, getmypid, glob, ini_set, is_array, is_dir, is_file, is_string, json_decode, memory_get_peak_usage, memory_get_usage, microtime, php_regex, php_uname, - posix_getuid, random_bytes, realpath, restore_error_handler, round, str_contains, str_replace, - strpos, strtoupper, sys_get_temp_dir, time, unlink, + posix_getuid, random_bytes, realpath, restore_error_handler, round, str_replace, strpos, + strtoupper, sys_get_temp_dir, time, unlink, }; use shirabe_seld_json_lint::ParsingException; use shirabe_symfony_console::application::Application as BaseApplication; @@ -300,7 +300,7 @@ impl Application { let message = exception.to_string(); if exception.is_instanceof::<TransportException>() - && str_contains(&message, "Unable to use a proxy") + && message.contains("Unable to use a proxy") { io.write_error3( "<error>The following exception indicates your proxy is misconfigured</error>", @@ -312,7 +312,7 @@ impl Application { if Platform::is_windows() && exception.is_instanceof::<TransportException>() - && str_contains(&message, "unable to get local issuer certificate") + && message.contains("unable to get local issuer certificate") { let avast_detect = glob("C:\\Program Files\\Avast*"); let avast_detect_pm = PhpMixed::List( diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs index 9ca4569c..4510b125 100644 --- a/crates/shirabe/src/dependency_resolver/problem.rs +++ b/crates/shirabe/src/dependency_resolver/problem.rs @@ -13,8 +13,8 @@ use indexmap::IndexMap; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ CmpOp, LogicException, PhpMixed, defined, extension_loaded, implode, loosely_compare, - php_regex, spl_object_hash, sprintf, str_replace, str_starts_with, stripos, strpos, strtolower, - substr, substr_count, version_compare, + php_regex, spl_object_hash, sprintf, str_replace, stripos, strpos, strtolower, substr, + substr_count, version_compare, }; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::MultiConstraint; @@ -806,7 +806,7 @@ impl Problem { ); } - if str_starts_with(advisory_id, "PKSA-") { + if advisory_id.starts_with("PKSA-") { return format!( "<href={}>{}</>", OutputFormatter::escape(&format!( @@ -828,7 +828,7 @@ impl Problem { ) .into_iter() .map(|advisory_id: String| { - if str_starts_with(&advisory_id, "PKSA-") { + if advisory_id.starts_with("PKSA-") { return format!( "<href={}>{}</>", OutputFormatter::escape(&format!( @@ -1384,7 +1384,7 @@ impl Problem { if let Some(c) = constraint && c.is_constraint() && c.get_operator() == Some(CmpOp::Eq) - && !str_starts_with(c.get_version(), "dev-") + && !c.get_version().starts_with("dev-") { if !Preg::is_match3( php_regex!(r"{^\d+(?:\.\d+)*$}"), diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index ddbb6788..e7f3facf 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -13,8 +13,8 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ CmpOp, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException, ZipArchive, bin2hex, class_exists, file_exists, file_get_contents, filesize, function_exists, hash_file, - impl_php_class, is_file, json_encode, php_regex, random_int, str_contains, str_replace, strlen, - substr, version_compare, + impl_php_class, is_file, json_encode, php_regex, random_int, str_replace, strlen, substr, + version_compare, }; use shirabe_symfony_process::ExecutableFinder; use std::sync::Mutex; @@ -202,7 +202,7 @@ impl ZipDownloader { return Err(process_error); } - if str_contains(&process_error.to_string(), "zip bomb") { + if process_error.to_string().contains("zip bomb") { return Err(process_error); } diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index ca6c2adc..d9ec9306 100644 --- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs +++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs @@ -32,8 +32,7 @@ use shirabe_php_shim::{ array_search_in_vec, array_splice, file_exists, get_class, hash, implode, ini_get, is_array, is_callable, is_object, is_string, krsort, php_regex, preg_quote, realpath, spl_autoload_functions, spl_autoload_register, spl_autoload_unregister, spl_object_hash, - str_contains, str_ends_with, str_replace, str_starts_with, strlen, strpos, strtoupper, substr, - trim, + str_replace, strlen, strpos, strtoupper, substr, trim, }; use shirabe_symfony_console::output::output_interface; use shirabe_symfony_process::ExecutableFinder; @@ -371,7 +370,7 @@ impl EventDispatcher { let mut additional_args = event.get_arguments().clone(); let mut callable = callable; if let Callable::String(ref s) = callable - && str_contains(s, "@no_additional_args") + && s.contains("@no_additional_args") { let replaced = Preg::replace(php_regex!("{ ?@no_additional_args}"), "", s); callable = Callable::String(replaced); @@ -880,7 +879,7 @@ try {{ // @putenv does not receive arguments let mut exec = if strpos(&callable_str, "@putenv ") == Some(0) { callable_str.clone() - } else if str_contains(&callable_str, "@additional_args") { + } else if callable_str.contains("@additional_args") { str_replace("@additional_args", &args, &callable_str) } else { format!( @@ -1358,16 +1357,14 @@ try {{ /// Checks if string given references a command class fn is_command_class(&self, callable: &str) -> bool { - str_contains(callable, "\\") - && !str_contains(callable, " ") - && str_ends_with(callable, "Command") + callable.contains("\\") && !callable.contains(" ") && callable.ends_with("Command") } /// Checks if string given references a composer run-script fn is_composer_script(&self, callable: &str) -> bool { - str_starts_with(callable, "@") - && !str_starts_with(callable, "@php ") - && !str_starts_with(callable, "@putenv ") + callable.starts_with("@") + && !callable.starts_with("@php ") + && !callable.starts_with("@putenv ") } /// Push an event to the stack of active event diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs index 7fdec9e1..8c26bdbc 100644 --- a/crates/shirabe/src/installer/installation_manager.rs +++ b/crates/shirabe/src/installer/installation_manager.rs @@ -24,7 +24,7 @@ use crate::util::sync_executor; use indexmap::IndexMap; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, array_splice, array_unshift, http_build_query, json_encode, - str_contains, str_replace, strpos, strtolower, + str_replace, strpos, strtolower, }; /// Package operation manager. @@ -844,7 +844,7 @@ impl InstallationManager { let result: anyhow::Result<()> = (|| -> anyhow::Result<()> { for (repo_url, packages) in self.notifiable_packages.borrow().iter() { // non-batch API, deprecated - if str_contains(repo_url, "%package%") { + if repo_url.contains("%package%") { for package in packages { let url = str_replace("%package%", &package.get_pretty_name(), repo_url); diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index b08a7a97..86dc0a2b 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -15,7 +15,7 @@ use shirabe_php_shim::{ InvalidArgumentException, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, PhpMixed, RuntimeException, UnexpectedValueException, dirname, file_exists, file_get_contents, file_put_contents, is_dir, is_file, json_decode, json_encode_ex, mkdir, php_regex, realpath, - str_contains, str_ends_with, str_repeat, strlen, strpos, usleep, + str_repeat, strlen, strpos, usleep, }; use shirabe_seld_json_lint::{ParsingException, ParsingExceptionDetails}; @@ -484,8 +484,8 @@ impl JsonFile { if matches!(data, PhpMixed::Null) && json != "null" { // attempt resolving simple conflicts in lock files so that one can run `composer update --lock` and get a valid lock file if let Some(file) = file - && str_ends_with(file, ".lock") - && str_contains(json, "\"content-hash\"") + && file.ends_with(".lock") + && json.contains("\"content-hash\"") { let mut count: usize = 0; let replaced = Preg::replace5( diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs index 5a77e771..bbd032e7 100644 --- a/crates/shirabe/src/json/json_manipulator.rs +++ b/crates/shirabe/src/json/json_manipulator.rs @@ -8,8 +8,8 @@ use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, addcslashes, array_key_exists, array_keys, array_reverse, empty, explode, implode, in_array_loose, is_array, is_int, is_numeric, - json_decode, php_regex, php_truthy, preg_quote, rtrim, str_contains, str_repeat, str_replace, - strlen, strnatcmp, strpos, substr, trim, uksort, + json_decode, php_regex, php_truthy, preg_quote, rtrim, str_repeat, str_replace, strlen, + strnatcmp, strpos, substr, trim, uksort, }; #[derive(Debug)] @@ -1061,7 +1061,7 @@ impl JsonManipulator { let mut item_depth: i64 = 1; // keep oneline lists as one line - if !str_contains(&whitespace, &self.newline) { + if !whitespace.contains(&self.newline) { leading_item_whitespace = leading_whitespace.clone(); trailing_item_whitespace = leading_whitespace.clone(); item_depth = 0; diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index 3e1f35ec..feb9388f 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -20,8 +20,8 @@ use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_rpc::PlatformInfo; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, UnexpectedValueException, array_map_str_fn, - array_slice_strs, explode, get_class, implode, is_string, php_regex, str_replace, - str_starts_with, strpos, strtolower, var_export, + array_slice_strs, explode, get_class, implode, is_string, php_regex, str_replace, strpos, + strtolower, var_export, }; use shirabe_semver::constraint::SimpleConstraint; use std::sync::{LazyLock, Mutex}; @@ -427,7 +427,7 @@ impl PlatformRepository { )?; } else { let (shortlib, ssl_lib); - if str_starts_with(&library, "(securetransport)") { + if library.starts_with("(securetransport)") { let mut securetransport_matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index b46e7913..2db41238 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -9,9 +9,8 @@ use shirabe_php_shim::{ clearstatcache, clearstatcache2, copy, dirname, explode, fclose, feof, file_exists, file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen, fread, function_exists, fwrite, implode, is_dir, is_file, is_link, is_readable, lstat, mkdir, - php_regex, rename, rmdir, rtrim, str_contains, str_repeat, str_replace, str_starts_with, - strlen, strpos, strtoupper, strtr, substr, substr_count, symlink, touch, unlink, usleep, - var_export, + php_regex, rename, rmdir, rtrim, str_repeat, str_replace, strlen, strpos, strtoupper, strtr, + substr, substr_count, symlink, touch, unlink, usleep, var_export, }; use shirabe_symfony_filesystem::exception::IOException; use shirabe_symfony_finder::Finder; @@ -431,7 +430,7 @@ impl Filesystem { // if copy fails we attempt to copy it manually as this can help bypass issues with VirtualBox shared folders // see https://github.com/composer/composer/issues/12057 - if str_contains(e.get_message(), "Bad address") { + if e.get_message().contains("Bad address") { let (source_handle, target_handle) = match (fopen(source, "r"), fopen(&target, "w")) { (Ok(source_handle), Ok(target_handle)) => { @@ -648,7 +647,7 @@ impl Filesystem { } common_path = format!("{}/", rtrim(&common_path, Some("/"))); - if str_starts_with(&to, &format!("{}/", from)) { + if to.starts_with(&format!("{}/", from)) { return format!( "__DIR__ . {}", var_export(&PhpMixed::String(substr(&to, strlen(&from), None)), true) diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index c92847a2..26ea1898 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -18,8 +18,8 @@ use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ AnyThrowable, CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, clearstatcache, explode, implode, in_array_loose, in_array_strict, is_dir, php_regex, - preg_quote, rawurldecode, rawurlencode, str_contains, str_ends_with, str_replace_array, strlen, - strpos, substr, trim, version_compare, + preg_quote, rawurldecode, rawurlencode, str_replace_array, strlen, strpos, substr, trim, + version_compare, }; use std::sync::Mutex; @@ -57,7 +57,7 @@ impl Git { path: &str, io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>, ) -> anyhow::Result<()> { - if str_contains(output, "fatal: detected dubious ownership") { + if output.contains("fatal: detected dubious ownership") { let msg = format!( "The repository at \"{}\" does not have the correct ownership and git refuses to use it:{}{}{}", path, PHP_EOL, PHP_EOL, output @@ -431,7 +431,7 @@ impl Git { let domain = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); let mut repo_with_git_part = m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default(); - if !str_ends_with(&repo_with_git_part, ".git") { + if !repo_with_git_part.ends_with(".git") { repo_with_git_part.push_str(".git"); } if !self.io.has_authentication(&domain) { @@ -651,7 +651,7 @@ impl Git { let mut m2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); let m3 = m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default(); let mut auth_parts: Option<String> = None; - if str_contains(&m2, "@") { + if m2.contains("@") { let parts = explode("@", &m2); auth_parts = parts.first().cloned(); m2 = parts.get(1).cloned().unwrap_or_default(); @@ -665,7 +665,7 @@ impl Git { if let Some(ref parts) = auth_parts && !parts.is_empty() { - if str_contains(parts, ":") { + if parts.contains(":") { let split = explode(":", parts); default_username = split.first().cloned(); } else { diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 596a634b..ccdd30b6 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -237,9 +237,7 @@ impl Platform { None => continue, }; // detect default mount points created by Docker/containerd - if shirabe_php_shim::str_contains(&data, "/var/lib/docker/") - || shirabe_php_shim::str_contains(&data, "/io.containerd.snapshotter") - { + if data.contains("/var/lib/docker/") || data.contains("/io.containerd.snapshotter") { *cached = Some(true); return true; } @@ -357,7 +355,7 @@ impl Platform { let mut output = String::new(); let result: anyhow::Result<()> = (|| { if process.execute_args(&["lsmod".to_string()], &mut output, None) == 0 - && shirabe_php_shim::str_contains(&output, "vboxguest") + && output.contains("vboxguest") { *cached = Some(true); return Ok(()); |
