aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-class-map-generator/src/php_file_parser.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-17 02:53:53 +0900
committernsfisis <nsfisis@gmail.com>2026-05-17 02:53:53 +0900
commita1c7e6908a26e10f6e1f23a51721664b5e2d838d (patch)
treec575c76f1b43359ed74913da4c6a2636643f1ba0 /crates/shirabe-class-map-generator/src/php_file_parser.rs
parent7f606f36fef0c0467c3c0db3d0da33af486dae8a (diff)
downloadphp-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.tar.gz
php-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.tar.zst
php-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.zip
chore(style): cargo fmt
Diffstat (limited to 'crates/shirabe-class-map-generator/src/php_file_parser.rs')
-rw-r--r--crates/shirabe-class-map-generator/src/php_file_parser.rs48
1 files changed, 33 insertions, 15 deletions
diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs
index b68a33a..9bc7c5c 100644
--- a/crates/shirabe-class-map-generator/src/php_file_parser.rs
+++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs
@@ -1,17 +1,15 @@
//! ref: composer/vendor/composer/class-map-generator/src/PhpFileParser.php
-use std::sync::OnceLock;
+use crate::php_file_cleaner::PhpFileCleaner;
use anyhow::anyhow;
use indexmap::IndexMap;
+use shirabe_external_packages::composer::pcre::preg::Preg;
use shirabe_php_shim::{
- PHP_EOL, PHP_VERSION_ID, HHVM_VERSION,
- RuntimeException,
- error_get_last, file_exists, file_get_contents, function_exists,
- is_file, is_readable, ltrim, php_strip_whitespace, sprintf,
+ HHVM_VERSION, PHP_EOL, PHP_VERSION_ID, RuntimeException, error_get_last, file_exists,
+ file_get_contents, function_exists, is_file, is_readable, ltrim, php_strip_whitespace, sprintf,
str_replace_array, strrpos, substr, trim, version_compare,
};
-use shirabe_external_packages::composer::pcre::preg::Preg;
-use crate::php_file_cleaner::PhpFileCleaner;
+use std::sync::OnceLock;
pub struct PhpFileParser;
@@ -38,11 +36,15 @@ impl PhpFileParser {
// The input file was really empty and thus contains no classes
return Ok(vec![]);
} else {
- message = "File at \"%s\" could not be parsed as PHP, it may be binary or corrupted";
+ message =
+ "File at \"%s\" could not be parsed as PHP, it may be binary or corrupted";
}
let error = error_get_last();
- let mut message = sprintf(message, &[shirabe_php_shim::PhpMixed::String(path.to_string())]);
+ let mut message = sprintf(
+ message,
+ &[shirabe_php_shim::PhpMixed::String(path.to_string())],
+ );
if let Some(error) = error {
if let Some(err_msg) = error.get("message") {
message = format!(
@@ -87,16 +89,33 @@ impl PhpFileParser {
let len = matches.get("type").map(|v| v.len()).unwrap_or(0);
for i in 0..len {
- let ns = matches.get("ns").and_then(|v| v.get(i)).map(|s| s.as_str()).unwrap_or("");
+ let ns = matches
+ .get("ns")
+ .and_then(|v| v.get(i))
+ .map(|s| s.as_str())
+ .unwrap_or("");
if !ns.is_empty() {
- let nsname = matches.get("nsname").and_then(|v| v.get(i)).map(|s| s.as_str()).unwrap_or("");
+ let nsname = matches
+ .get("nsname")
+ .and_then(|v| v.get(i))
+ .map(|s| s.as_str())
+ .unwrap_or("");
namespace = str_replace_array(
- &[" ".to_string(), "\t".to_string(), "\r".to_string(), "\n".to_string()],
+ &[
+ " ".to_string(),
+ "\t".to_string(),
+ "\r".to_string(),
+ "\n".to_string(),
+ ],
&["".to_string()],
nsname,
) + "\\";
} else {
- let name = matches.get("name").and_then(|v| v.get(i)).map(|s| s.as_str()).unwrap_or("");
+ let name = matches
+ .get("name")
+ .and_then(|v| v.get(i))
+ .map(|s| s.as_str())
+ .unwrap_or("");
// skip anon classes extending/implementing
if name == "extends" {
continue;
@@ -151,8 +170,7 @@ impl PhpFileParser {
let mut extra_types = String::new();
let mut extra_types_array: Vec<String> = vec![];
if PHP_VERSION_ID >= 80100
- || (HHVM_VERSION.is_some()
- && version_compare(HHVM_VERSION.unwrap(), "3.3", ">="))
+ || (HHVM_VERSION.is_some() && version_compare(HHVM_VERSION.unwrap(), "3.3", ">="))
{
extra_types += "|enum";
extra_types_array = vec!["enum".to_string()];