From fce44d4587ba11b080fe0266c483d0be684ffd0d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 12:51:24 +0900 Subject: refactor(php-shim): split json_decode into assoc and obj variants The assoc flag was always a literal at every call site, so the boolean carried no information the function name could not. json_decode_assoc and json_decode_obj make the resulting PhpMixed shape visible at the call site. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/util/auth_helper.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'crates/shirabe/src/util/auth_helper.rs') diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs index 3b8aa2e7..7d47f088 100644 --- a/crates/shirabe/src/util/auth_helper.rs +++ b/crates/shirabe/src/util/auth_helper.rs @@ -12,7 +12,8 @@ use indexmap::IndexMap; use shirabe_pcre::Preg; use shirabe_php_shim::{ PhpMixed, RuntimeException, base64_encode, explode, in_array_loose, in_array_strict, is_array, - is_string, json_decode, parse_url, php_regex, str_replace, strpos, strtolower, substr, trim, + is_string, json_decode_assoc, parse_url, php_regex, str_replace, strpos, strtolower, substr, + trim, }; #[derive(Debug)] @@ -189,7 +190,7 @@ impl AuthHelper { // Try to extract a more specific error message from GitHub's API response let mut git_hub_api_message: Option = None; if let Some(body) = response_body { - let decoded = json_decode(body, true)?; + let decoded = json_decode_assoc(body)?; if is_array(&decoded) && let Some(arr) = decoded.as_array() && let Some(msg) = arr.get("message") @@ -520,7 +521,7 @@ impl AuthHelper { let mut custom_headers: PhpMixed = PhpMixed::Null; // PHP: if (is_string($auth['username'])) // username field is always String in our IndexMap representation - custom_headers = json_decode(&username, true)?; + custom_headers = json_decode_assoc(&username)?; if is_array(&custom_headers) { if let Some(arr) = custom_headers.as_array() { for header in arr.values() { @@ -580,12 +581,12 @@ impl AuthHelper { Some("Using Bitbucket OAuth token authentication".to_string()); } } else if username == "client-certificate" { - // PHP: $options['ssl'] = array_merge($options['ssl'] ?? [], json_decode((string) $auth['password'], true)); + // PHP: $options['ssl'] = array_merge($options['ssl'] ?? [], json_decode_assoc((string) $auth['password'])); let existing_ssl = options .get("ssl") .cloned() .unwrap_or(PhpMixed::Array(IndexMap::new())); - let decoded = json_decode(&password, true)?; + let decoded = json_decode_assoc(&password)?; options.insert( "ssl".to_string(), shirabe_php_shim::array_merge(existing_ssl, decoded), -- cgit v1.3.1-4-g156e