diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs | 28 | ||||
| -rw-r--r-- | crates/shirabe-php-shim/src/array.rs | 12 | ||||
| -rw-r--r-- | crates/shirabe/src/command/config_command.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/command/diagnose_command.rs | 12 | ||||
| -rw-r--r-- | crates/shirabe/src/config.rs | 18 | ||||
| -rw-r--r-- | crates/shirabe/src/util/filesystem.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/tests/config_test.rs | 1 |
8 files changed, 51 insertions, 35 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs index 64f0687..24d434d 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 @@ -221,9 +221,10 @@ impl ChoiceQuestion { return Ok(PhpMixed::List(multiselect_choices)); } - Ok(shirabe_php_shim::current(PhpMixed::List( - multiselect_choices, - ))) + Ok(multiselect_choices + .into_iter() + .next() + .unwrap_or(PhpMixed::Bool(false))) }) } } 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 83229a9..4b945b0 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 @@ -171,9 +171,31 @@ impl SymfonyStyle { todo!() } // $headers[] = key($value); $row[] = current($value); - let _ = shirabe_php_shim::key(value.clone()); - headers.push(todo!()); - row.push(shirabe_php_shim::current(value)); + let (first_key, first_value) = match &value { + PhpMixed::Array(entries) => ( + entries + .keys() + .next() + .map(|k| PhpMixed::String(k.clone())) + .unwrap_or(PhpMixed::Null), + entries + .values() + .next() + .cloned() + .unwrap_or(PhpMixed::Bool(false)), + ), + PhpMixed::List(items) => ( + if items.is_empty() { + PhpMixed::Null + } else { + PhpMixed::Int(0) + }, + items.first().cloned().unwrap_or(PhpMixed::Bool(false)), + ), + _ => unreachable!("value is an array past the is_array guard"), + }; + headers.push(first_key); + row.push(first_value); } self.horizontal_table(headers, vec![PhpMixed::List(row.into_iter().collect())]); diff --git a/crates/shirabe-php-shim/src/array.rs b/crates/shirabe-php-shim/src/array.rs index dc06b01..e7738cc 100644 --- a/crates/shirabe-php-shim/src/array.rs +++ b/crates/shirabe-php-shim/src/array.rs @@ -701,14 +701,6 @@ pub fn count(value: &PhpMixed) -> usize { } } -pub fn current(_value: PhpMixed) -> PhpMixed { - todo!() -} - -pub fn key(_value: PhpMixed) -> Option<String> { - todo!() -} - pub fn reset<T: Clone>(_array: &[T]) -> Option<T> { _array.first().cloned() } @@ -727,7 +719,3 @@ where { iter.into_iter().collect() } - -pub fn end<V: Clone>(_array: &[V]) -> Option<V> { - _array.last().cloned() -} 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; diff --git a/crates/shirabe/tests/config_test.rs b/crates/shirabe/tests/config_test.rs index 6eddf9b..b91237e 100644 --- a/crates/shirabe/tests/config_test.rs +++ b/crates/shirabe/tests/config_test.rs @@ -140,7 +140,6 @@ fn data_add_packagist_repository() -> Vec<Case> { } #[test] -#[ignore = "Config::merge of an anonymous {name: false} disable entry reaches current() (todo!()) in the php-shim"] fn test_add_packagist_repository() { for case in data_add_packagist_repository() { let mut config = Config::new(false, None); |
