aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 12:51:24 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 12:51:24 +0900
commitfce44d4587ba11b080fe0266c483d0be684ffd0d (patch)
tree753e87ac7ed2e57d635a60c10a4ce01b7e0f0f8e /crates/shirabe/src/util
parentb12c2b15f0487d54d359a581e99ced68713914d0 (diff)
downloadphp-shirabe-fce44d4587ba11b080fe0266c483d0be684ffd0d.tar.gz
php-shirabe-fce44d4587ba11b080fe0266c483d0be684ffd0d.tar.zst
php-shirabe-fce44d4587ba11b080fe0266c483d0be684ffd0d.zip
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/auth_helper.rs11
-rw-r--r--crates/shirabe/src/util/gitlab.rs5
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs2
-rw-r--r--crates/shirabe/src/util/perforce.rs4
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs4
5 files changed, 14 insertions, 12 deletions
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<String> = 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),
diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs
index ef68c82f..52707b5b 100644
--- a/crates/shirabe/src/util/gitlab.rs
+++ b/crates/shirabe/src/util/gitlab.rs
@@ -12,7 +12,8 @@ use indexmap::IndexMap;
use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, http_build_query, in_array_strict, json_decode, php_regex, time,
+ PhpMixed, RuntimeException, http_build_query, in_array_strict, json_decode_assoc, php_regex,
+ time,
};
#[derive(Debug)]
@@ -253,7 +254,7 @@ impl GitLab {
Some(te) if te.get_code() == 403 || te.get_code() == 401 => {
if te.get_code() == 401 {
let response =
- te.get_response().and_then(|r| json_decode(r, true).ok());
+ te.get_response().and_then(|r| json_decode_assoc(r).ok());
let is_invalid_grant = response
.as_ref()
.and_then(|r| r.as_array())
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index 742e0fd3..6140bb08 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -339,7 +339,7 @@ impl CurlDownloader {
&& curl_response.inner.get_header("content-type").as_deref() == Some("application/json")
&& let Some(body) = curl_response.inner.get_body()
{
- let decoded = shirabe_php_shim::json_decode(body, true)?;
+ let decoded = shirabe_php_shim::json_decode_assoc(body)?;
if let PhpMixed::Array(a) = decoded {
HttpDownloader::output_warnings(self.io.clone(), origin, &a)?;
}
diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs
index fbab6889..c0cd5a08 100644
--- a/crates/shirabe/src/util/perforce.rs
+++ b/crates/shirabe/src/util/perforce.rs
@@ -9,7 +9,7 @@ use indexmap::IndexMap;
use shirabe_pcre::Preg;
use shirabe_php_shim::{
Exception, PHP_EOL, PhpMixed, PhpResource, chdir, date_local, explode, fclose, feof, fgets,
- file_get_contents, fopen, fwrite, gethostname, json_decode, php_regex, str_replace_array,
+ file_get_contents, fopen, fwrite, gethostname, json_decode_assoc, php_regex, str_replace_array,
strcmp, strlen, strpos, strrpos, substr, time, trim,
};
use shirabe_symfony_process::ExecutableFinder;
@@ -577,7 +577,7 @@ impl Perforce {
Some(s) => s,
};
- let decoded = json_decode(&composer_file_content, true)?;
+ let decoded = json_decode_assoc(&composer_file_content)?;
Ok(match decoded {
PhpMixed::Array(m) => Some(m.into_iter().collect()),
_ => None,
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index 61165b28..4a8ca267 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -19,7 +19,7 @@ use shirabe_php_shim::{
PhpMixed, RuntimeException, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS,
STREAM_NOTIFY_PROGRESS, array_replace_recursive, base64_encode, explode, extension_loaded,
file_get_contents, file_get_contents5, file_put_contents, filter_var_boolean, gethostbyname,
- http_clear_last_response_headers, http_get_last_response_headers, ini_get, json_decode,
+ http_clear_last_response_headers, http_get_last_response_headers, ini_get, json_decode_assoc,
parse_url, php_regex, preg_quote, strpos, strtolower, strtr, substr, trim, zlib_decode,
};
@@ -336,7 +336,7 @@ impl RemoteFilesystem {
{
let parsed = result
.as_deref()
- .map(|s| json_decode(s, true).unwrap_or(PhpMixed::Null))
+ .map(|s| json_decode_assoc(s).unwrap_or(PhpMixed::Null))
.unwrap_or(PhpMixed::Null);
let parsed_map: IndexMap<String, PhpMixed> = match parsed {
PhpMixed::Array(m) => m.into_iter().collect(),