aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/json/json_file.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/json/json_file.rs')
-rw-r--r--crates/shirabe/src/json/json_file.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index c6ec3cd..cdb9ba7 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -6,12 +6,12 @@ use shirabe_external_packages::json_schema::validator::Validator;
use shirabe_external_packages::seld::json_lint::json_parser::JsonParser;
use shirabe_external_packages::seld::json_lint::parsing_exception::ParsingException;
use shirabe_php_shim::{
+ InvalidArgumentException, JSON_ERROR_CTRL_CHAR, JSON_ERROR_DEPTH, JSON_ERROR_NONE,
+ JSON_ERROR_STATE_MISMATCH, JSON_ERROR_UTF8, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES,
+ JSON_UNESCAPED_UNICODE, PhpMixed, RuntimeException, Silencer, UnexpectedValueException,
defined, dirname, file_exists, file_get_contents, file_put_contents, is_dir, is_file,
json_decode, json_encode_ex, json_last_error, mkdir, php_dir, realpath, str_contains,
- str_ends_with, str_repeat, strlen, strpos, usleep, InvalidArgumentException, PhpMixed,
- RuntimeException, Silencer, UnexpectedValueException, JSON_ERROR_CTRL_CHAR, JSON_ERROR_DEPTH,
- JSON_ERROR_NONE, JSON_ERROR_STATE_MISMATCH, JSON_ERROR_UTF8, JSON_PRETTY_PRINT,
- JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE,
+ str_ends_with, str_repeat, strlen, strpos, usleep,
};
use crate::downloader::transport_exception::TransportException;
@@ -236,7 +236,9 @@ impl JsonFile {
/// @return int|false
fn file_put_contents_if_modified(&self, path: &str, content: &str) -> Result<Option<i64>> {
// PHP: @file_get_contents($path)
- let current_content = Silencer::call(|| Ok(file_get_contents(path))).ok().flatten();
+ let current_content = Silencer::call(|| Ok(file_get_contents(path)))
+ .ok()
+ .flatten();
if current_content.is_none() || current_content.as_deref() != Some(content) {
return Ok(file_put_contents(path, content.as_bytes()));
}
@@ -518,11 +520,18 @@ impl JsonFile {
let result = result.unwrap();
Err(match file {
None => ParsingException::new(
- format!("The input does not contain valid JSON\n{}", result.get_message()),
+ format!(
+ "The input does not contain valid JSON\n{}",
+ result.get_message()
+ ),
result.get_details(),
),
Some(f) => ParsingException::new(
- format!("\"{}\" does not contain valid JSON\n{}", f, result.get_message()),
+ format!(
+ "\"{}\" does not contain valid JSON\n{}",
+ f,
+ result.get_message()
+ ),
result.get_details(),
),
}
@@ -530,10 +539,7 @@ impl JsonFile {
}
pub fn detect_indenting(json: Option<&str>) -> String {
- if let Some(m) = Preg::is_match_strict_groups(
- r##"#^([ \t]+)"#m"##,
- json.unwrap_or(""),
- ) {
+ if let Some(m) = Preg::is_match_strict_groups(r##"#^([ \t]+)"#m"##, json.unwrap_or("")) {
return m.get(1).cloned().unwrap_or_default();
}