aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/autoload
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 01:16:50 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 02:22:41 +0900
commitefec43b3b8827820cf35fe1b73d8e33f5fe84eb4 (patch)
treea62bbba72324de48be5f8e689559f8d9e288fc61 /crates/shirabe/src/autoload
parentcac18ef73a39b4ac41fa4d6ccb753804d4c42cb7 (diff)
downloadphp-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.gz
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.zst
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.zip
refactor: auto-fix clippy warnings
Diffstat (limited to 'crates/shirabe/src/autoload')
-rw-r--r--crates/shirabe/src/autoload/autoload_generator.rs99
-rw-r--r--crates/shirabe/src/autoload/class_loader.rs45
2 files changed, 67 insertions, 77 deletions
diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs
index 6ceb02c..c69cd34 100644
--- a/crates/shirabe/src/autoload/autoload_generator.rs
+++ b/crates/shirabe/src/autoload/autoload_generator.rs
@@ -104,6 +104,7 @@ impl AutoloadGenerator {
self.platform_requirement_filter = platform_requirement_filter;
}
+ #[allow(clippy::too_many_arguments, reason = "to keep PHP signature")]
pub fn dump(
&mut self,
config: &Config,
@@ -137,10 +138,10 @@ impl AutoloadGenerator {
)?;
if installed_json.exists() {
let installed_json_data = installed_json.read()?;
- if let Some(arr) = installed_json_data.as_array() {
- if let Some(dev) = arr.get("dev") {
- self.dev_mode = dev.as_bool();
- }
+ if let Some(arr) = installed_json_data.as_array()
+ && let Some(dev) = arr.get("dev")
+ {
+ self.dev_mode = dev.as_bool();
}
}
}
@@ -310,7 +311,7 @@ impl AutoloadGenerator {
&& main_autoload
.get("psr-0")
.and_then(|v| v.as_array())
- .map_or(false, |a| !a.is_empty())
+ .is_some_and(|a| !a.is_empty())
{
let levels = substr_count(
&filesystem.normalize_path(&root_package.get_target_dir().unwrap_or_default()),
@@ -341,13 +342,12 @@ impl AutoloadGenerator {
if let Some(ex) = autoloads
.get("exclude-from-classmap")
.and_then(|v| v.as_list())
+ && !ex.is_empty()
{
- if !ex.is_empty() {
- excluded = ex
- .iter()
- .filter_map(|v| v.as_string().map(|s| s.to_string()))
- .collect();
- }
+ excluded = ex
+ .iter()
+ .filter_map(|v| v.as_string().map(|s| s.to_string()))
+ .collect();
}
let classmap_list = autoloads
@@ -383,7 +383,7 @@ impl AutoloadGenerator {
entry.insert("type".to_string(), PhpMixed::String(psr_type.to_string()));
namespaces_to_scan
.entry(namespace.clone())
- .or_insert_with(Vec::new)
+ .or_default()
.push(entry);
}
}
@@ -487,7 +487,7 @@ impl AutoloadGenerator {
for (class_name, path) in class_map.get_map() {
let path_code = format!(
"{},\n",
- self.get_path_code(&filesystem, &base_path, &vendor_path, &path)
+ self.get_path_code(&filesystem, &base_path, &vendor_path, path)
);
classmap_file.push_str(&format!(
" {} => {}",
@@ -608,7 +608,7 @@ impl AutoloadGenerator {
platform_check_content = self.get_platform_check(
&package_map,
config.get("platform-check").clone(),
- &dev_package_names,
+ dev_package_names,
);
if platform_check_content.is_none() {
check_platform = false;
@@ -750,7 +750,7 @@ impl AutoloadGenerator {
if autoload
.get("psr-4")
.and_then(|v| v.as_array())
- .map_or(false, |a| !a.is_empty())
+ .is_some_and(|a| !a.is_empty())
&& package.get_target_dir().is_some()
{
let name = package.get_name();
@@ -883,13 +883,12 @@ impl AutoloadGenerator {
if let Some(ex) = autoloads
.get("exclude-from-classmap")
.and_then(|v| v.as_list())
+ && !ex.is_empty()
{
- if !ex.is_empty() {
- excluded = ex
- .iter()
- .filter_map(|v| v.as_string().map(|s| s.to_string()))
- .collect();
- }
+ excluded = ex
+ .iter()
+ .filter_map(|v| v.as_string().map(|s| s.to_string()))
+ .collect();
}
let mut class_map_generator = ClassMapGenerator::new(vec![
@@ -943,11 +942,11 @@ impl AutoloadGenerator {
};
let mut install_path = install_path;
- if let Some(target_dir) = package.get_target_dir() {
- if !target_dir.is_empty() {
- let suffix_to_remove = format!("/{}", target_dir);
- install_path = substr(&install_path, 0, Some(-(suffix_to_remove.len() as i64)));
- }
+ if let Some(target_dir) = package.get_target_dir()
+ && !target_dir.is_empty()
+ {
+ let suffix_to_remove = format!("/{}", target_dir);
+ install_path = substr(&install_path, 0, Some(-(suffix_to_remove.len() as i64)));
}
for include_path in package.get_include_paths() {
@@ -1077,7 +1076,7 @@ impl AutoloadGenerator {
&self,
package_map: &Vec<(PackageInterfaceHandle, Option<String>)>,
check_platform: PhpMixed,
- dev_package_names: &Vec<String>,
+ dev_package_names: &[String],
) -> Option<String> {
let mut lowest_php_version = Bound::zero();
let mut required_php_64bit = false;
@@ -1092,13 +1091,13 @@ impl AutoloadGenerator {
let links = array_merge_map(package.get_replaces(), package.get_provides());
for (_k, link) in &links {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3("{^ext-(.+)$}iD", link.get_target(), Some(&mut matches)) {
- if let Some(ext) = matches.get(&CaptureKey::ByIndex(1)).cloned() {
- extension_providers
- .entry(ext)
- .or_insert_with(Vec::new)
- .push(link.get_constraint().clone());
- }
+ if Preg::match3("{^ext-(.+)$}iD", link.get_target(), Some(&mut matches))
+ && let Some(ext) = matches.get(&CaptureKey::ByIndex(1)).cloned()
+ {
+ extension_providers
+ .entry(ext)
+ .or_default()
+ .push(link.get_constraint().clone());
}
}
}
@@ -1144,7 +1143,7 @@ impl AutoloadGenerator {
// skip extension checks if they have a valid provider/replacer
if let Some(provided_list) = extension_providers.get(&ext_key) {
for provided in provided_list {
- if provided.matches(&*link.get_constraint()) {
+ if provided.matches(link.get_constraint()) {
continue 'outer;
}
}
@@ -1299,6 +1298,7 @@ impl AutoloadGenerator {
}
/// Note: vendor_path_code and app_base_dir_code are unused in this method
+ #[allow(clippy::too_many_arguments, reason = "to keep PHP signature")]
pub(crate) fn get_autoload_real_file(
&self,
_use_class_map: bool,
@@ -1413,7 +1413,7 @@ impl AutoloadGenerator {
} else {
vec![]
};
- loader.set(&namespace, paths);
+ loader.set(namespace, paths);
}
}
@@ -1428,20 +1428,21 @@ impl AutoloadGenerator {
} else {
vec![]
};
- loader.set_psr4(&namespace, paths).unwrap_or(());
+ loader.set_psr4(namespace, paths).unwrap_or(());
}
}
let class_map =
shirabe_php_shim::php_require(&format!("{}/autoload_classmap.php", target_dir));
- if class_map.as_bool() != Some(false) && !class_map.is_null() {
- if let Some(cm) = class_map.as_array() {
- let cm_str: IndexMap<String, String> = cm
- .iter()
- .map(|(k, v)| (k.clone(), v.as_string().unwrap_or("").to_string()))
- .collect();
- loader.add_class_map(cm_str);
- }
+ if class_map.as_bool() != Some(false)
+ && !class_map.is_null()
+ && let Some(cm) = class_map.as_array()
+ {
+ let cm_str: IndexMap<String, String> = cm
+ .iter()
+ .map(|(k, v)| (k.clone(), v.as_string().unwrap_or("").to_string()))
+ .collect();
+ loader.add_class_map(cm_str);
}
let filesystem = Filesystem::new(None);
@@ -1564,7 +1565,7 @@ impl AutoloadGenerator {
{
continue;
}
- maps.insert(substr(&prop, prefix_len as i64, None), value);
+ maps.insert(substr(&prop, prefix_len, None), value);
}
for (prop, value) in &maps {
@@ -1905,10 +1906,8 @@ impl AutoloadGenerator {
paths.insert(name, path.clone());
}
- let sorted_packages = PackageSorter::sort_packages(
- packages.values().map(|p| p.clone()).collect(),
- IndexMap::new(),
- );
+ let sorted_packages =
+ PackageSorter::sort_packages(packages.values().cloned().collect(), IndexMap::new());
let mut sorted_package_map: Vec<(PackageInterfaceHandle, Option<String>)> = vec![];
diff --git a/crates/shirabe/src/autoload/class_loader.rs b/crates/shirabe/src/autoload/class_loader.rs
index 083e1c3..918b319 100644
--- a/crates/shirabe/src/autoload/class_loader.rs
+++ b/crates/shirabe/src/autoload/class_loader.rs
@@ -134,7 +134,7 @@ impl ClassLoader {
if prefix.is_empty() {
if prepend {
let mut new_dirs = paths.clone();
- new_dirs.extend(self.fallback_dirs_psr0.drain(..));
+ new_dirs.append(&mut self.fallback_dirs_psr0);
self.fallback_dirs_psr0 = new_dirs;
} else {
self.fallback_dirs_psr0.extend(paths);
@@ -144,10 +144,7 @@ impl ClassLoader {
}
let first = prefix.chars().next().unwrap_or('\0').to_string();
- let entry = self
- .prefixes_psr0
- .entry(first.clone())
- .or_insert_with(IndexMap::new);
+ let entry = self.prefixes_psr0.entry(first.clone()).or_default();
if !entry.contains_key(prefix) {
entry.insert(prefix.to_string(), paths);
return;
@@ -155,7 +152,7 @@ impl ClassLoader {
let existing = entry.get_mut(prefix).unwrap();
if prepend {
let mut new_dirs = paths.clone();
- new_dirs.extend(existing.drain(..));
+ new_dirs.append(existing);
*existing = new_dirs;
} else {
existing.extend(paths);
@@ -176,7 +173,7 @@ impl ClassLoader {
// Register directories for the root namespace.
if prepend {
let mut new_dirs = paths.clone();
- new_dirs.extend(self.fallback_dirs_psr4.drain(..));
+ new_dirs.append(&mut self.fallback_dirs_psr4);
self.fallback_dirs_psr4 = new_dirs;
} else {
self.fallback_dirs_psr4.extend(paths);
@@ -195,14 +192,14 @@ impl ClassLoader {
let first = prefix.chars().next().unwrap_or('\0').to_string();
self.prefix_lengths_psr4
.entry(first)
- .or_insert_with(IndexMap::new)
+ .or_default()
.insert(prefix.to_string(), length);
self.prefix_dirs_psr4.insert(prefix.to_string(), paths);
} else if prepend {
// Prepend directories for an already registered namespace.
let existing = self.prefix_dirs_psr4.get_mut(prefix).unwrap();
let mut new_dirs = paths.clone();
- new_dirs.extend(existing.drain(..));
+ new_dirs.append(existing);
*existing = new_dirs;
} else {
// Append directories for an already registered namespace.
@@ -221,7 +218,7 @@ impl ClassLoader {
let first = prefix.chars().next().unwrap_or('\0').to_string();
self.prefixes_psr0
.entry(first)
- .or_insert_with(IndexMap::new)
+ .or_default()
.insert(prefix.to_string(), paths);
}
}
@@ -246,7 +243,7 @@ impl ClassLoader {
let first = prefix.chars().next().unwrap_or('\0').to_string();
self.prefix_lengths_psr4
.entry(first)
- .or_insert_with(IndexMap::new)
+ .or_default()
.insert(prefix.to_string(), length);
self.prefix_dirs_psr4.insert(prefix.to_string(), paths);
}
@@ -327,11 +324,8 @@ impl ClassLoader {
pub fn unregister(&self) {
spl_autoload_unregister(Box::new(|_class: &str| -> PhpMixed { PhpMixed::Null }));
- if self.vendor_dir.is_some() {
- REGISTERED_LOADERS
- .lock()
- .unwrap()
- .shift_remove(self.vendor_dir.as_ref().unwrap());
+ if let Some(vendor_dir) = &self.vendor_dir {
+ REGISTERED_LOADERS.lock().unwrap().shift_remove(vendor_dir);
}
}
@@ -360,12 +354,9 @@ impl ClassLoader {
if self.class_map_authoritative || self.missing_classes.contains_key(class) {
return None;
}
- if self.apcu_prefix.is_some() {
+ if let Some(apcu_prefix) = &self.apcu_prefix {
let mut hit = false;
- let file = apcu_fetch(
- &format!("{}{}", self.apcu_prefix.as_ref().unwrap(), class),
- &mut hit,
- );
+ let file = apcu_fetch(&format!("{}{}", apcu_prefix, class), &mut hit);
if hit {
return file.as_string().map(String::from);
}
@@ -378,9 +369,9 @@ impl ClassLoader {
file = self.find_file_with_extension(class, ".hh");
}
- if self.apcu_prefix.is_some() {
+ if let Some(apcu_prefix) = &self.apcu_prefix {
apcu_add(
- &format!("{}{}", self.apcu_prefix.as_ref().unwrap(), class),
+ &format!("{}{}", apcu_prefix, class),
match file.as_ref() {
Some(s) => PhpMixed::String(s.clone()),
None => PhpMixed::Bool(false),
@@ -483,10 +474,10 @@ impl ClassLoader {
}
// PSR-0 include paths.
- if self.use_include_path {
- if let Some(file) = stream_resolve_include_path(&logical_path_psr0) {
- return Some(file);
- }
+ if self.use_include_path
+ && let Some(file) = stream_resolve_include_path(&logical_path_psr0)
+ {
+ return Some(file);
}
None