aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-21 20:23:04 +0900
committernsfisis <nsfisis@gmail.com>2026-06-21 20:23:04 +0900
commite4402e52c08b8b28497151302c994793ce885cc3 (patch)
treeb1a12dd3941c95d1b64ed4f38a38902eecf2ff18 /crates/shirabe/src
parentaa270b53045cc1ce779447f4f19448236e9c4c67 (diff)
downloadphp-shirabe-e4402e52c08b8b28497151302c994793ce885cc3.tar.gz
php-shirabe-e4402e52c08b8b28497151302c994793ce885cc3.tar.zst
php-shirabe-e4402e52c08b8b28497151302c994793ce885cc3.zip
refactor(php-shim): drop current()/key()/end() array helpers
PHP's internal array pointer (current/key/end) has no clean Rust equivalent. Remove these todo!() shim stubs and replace each call site with direct first/last element access matching Composer's original behavior. Unblocks Config::merge of anonymous {name: false} disable entries, re-enabling test_add_packagist_repository. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src')
-rw-r--r--crates/shirabe/src/command/config_command.rs4
-rw-r--r--crates/shirabe/src/command/diagnose_command.rs12
-rw-r--r--crates/shirabe/src/config.rs18
-rw-r--r--crates/shirabe/src/util/filesystem.rs4
4 files changed, 22 insertions, 16 deletions
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 2ee6fd2..7dcd6bf 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -13,8 +13,8 @@ use shirabe_php_shim::{
InvalidArgumentException, JsonObject, PhpMixed, RuntimeException, array_filter,
array_filter_use_key, array_is_list, array_map, array_merge, array_unique, count,
escapeshellcmd, exec, explode, file_exists, file_get_contents, implode, in_array, is_array,
- is_bool, is_dir, is_numeric, is_object, is_string, json_encode, key, sort, sprintf,
- str_replace, str_starts_with, strpos, strtolower, system, touch, var_export,
+ is_bool, is_dir, is_numeric, is_object, is_string, json_encode, sort, sprintf, str_replace,
+ str_starts_with, strpos, strtolower, system, touch, var_export,
};
use std::cell::RefCell;
use std::rc::Rc;
diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs
index 4b1c241..1210956 100644
--- a/crates/shirabe/src/command/diagnose_command.rs
+++ b/crates/shirabe/src/command/diagnose_command.rs
@@ -15,8 +15,8 @@ use shirabe_php_shim::{
PHP_VERSION, PHP_VERSION_ID, PHP_WINDOWS_VERSION_BUILD, PhpMixed, RuntimeException, count,
curl_version, defined, disk_free_space, extension_loaded, file_exists, filter_var_boolean,
function_exists, get_class, get_class_err, hash, implode, ini_get, ioncube_loader_iversion,
- ioncube_loader_version, is_array, is_string, key, ob_get_clean, ob_start, phpinfo, reset,
- rtrim, sprintf, str_contains, str_replace, str_starts_with, strpos, strstr, strtolower, trim,
+ ioncube_loader_version, is_array, is_string, ob_get_clean, ob_start, phpinfo, reset, rtrim,
+ sprintf, str_contains, str_replace, str_starts_with, strpos, strstr, strtolower, trim,
version_compare,
};
use std::cell::RefCell;
@@ -690,12 +690,10 @@ impl DiagnoseCommand {
let path = str_replace(
"%hash%",
hash_val.as_string().unwrap_or(""),
- &key(provider_includes
+ &provider_includes
.as_array()
- .cloned()
- .unwrap_or_default()
- .into())
- .unwrap_or_default(),
+ .and_then(|a| a.keys().next().cloned())
+ .unwrap_or_default(),
);
let response = self.http_downloader.as_ref().unwrap().borrow_mut().get(
&format!("{}://repo.packagist.org/{}", protocol, path),
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs
index bb46483..dfc99a6 100644
--- a/crates/shirabe/src/config.rs
+++ b/crates/shirabe/src/config.rs
@@ -12,9 +12,9 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
E_USER_DEPRECATED, PHP_URL_HOST, PHP_URL_SCHEME, PhpMixed, RuntimeException, array_key_exists,
- array_merge, array_reverse, array_search_mixed, array_unique, current, empty, filter_var_url,
- implode, in_array, is_array, is_int, is_string, key, parse_url, php_to_string, reset, rtrim,
- strtolower, strtoupper, strtr, substr, trigger_error,
+ array_merge, array_reverse, array_search_mixed, array_unique, empty, filter_var_url, implode,
+ in_array, is_array, is_int, is_string, parse_url, php_to_string, reset, rtrim, strtolower,
+ strtoupper, strtr, substr, trigger_error,
};
use std::cell::RefCell;
@@ -465,9 +465,17 @@ impl Config {
// disable a repository with an anonymous {"name": false} repo
if is_array(repository)
&& repository.as_array().map(|m| m.len()).unwrap_or(0) == 1
- && matches!(current(repository.clone()), PhpMixed::Bool(false))
+ && matches!(
+ repository.as_array().and_then(|m| m.values().next()),
+ Some(PhpMixed::Bool(false))
+ )
{
- self.disable_repo_by_name(&key(repository.clone()).unwrap_or_default());
+ let name = repository
+ .as_array()
+ .and_then(|m| m.keys().next())
+ .cloned()
+ .unwrap_or_default();
+ self.disable_repo_by_name(&name);
continue;
}
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 7a4885a..37ffabb 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -6,7 +6,7 @@ use shirabe_external_packages::symfony::finder::Finder;
use shirabe_php_shim::{
DIRECTORY_SEPARATOR, ErrorException, InvalidArgumentException, LogicException, PhpMixed,
RuntimeException, UnexpectedValueException, array_pop, basename, chdir, clearstatcache,
- clearstatcache2, copy, count, dirname, end, error_get_last, explode, fclose, feof, file_exists,
+ clearstatcache2, copy, count, dirname, error_get_last, explode, fclose, feof, file_exists,
file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen, fread,
function_exists, fwrite, implode, is_array, is_dir, is_file, is_link, is_readable, lstat,
mkdir, react_promise_resolve, rename, rmdir, rtrim, sprintf, str_contains, str_repeat,
@@ -739,7 +739,7 @@ impl Filesystem {
for chunk in explode("/", &path) {
if ".." == chunk && (strlen(&absolute) > 0 || up) {
array_pop(&mut parts);
- up = !(parts.is_empty() || ".." == end(&parts).unwrap_or_default());
+ up = !(parts.is_empty() || ".." == parts.last().cloned().unwrap_or_default());
} else if "." != chunk && !chunk.is_empty() {
parts.push(chunk.clone());
up = ".." != chunk;