aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-05 05:49:22 +0900
committernsfisis <nsfisis@gmail.com>2026-06-05 05:49:22 +0900
commit7d3a88cb55f101f376a6635ea7dcbb0e10eff364 (patch)
treec00f88d007f93075e070c514e4fb39150aaaa1a7 /crates/shirabe
parent56186a770b693217aad456a153208d8fdaa13f21 (diff)
downloadphp-shirabe-7d3a88cb55f101f376a6635ea7dcbb0e10eff364.tar.gz
php-shirabe-7d3a88cb55f101f376a6635ea7dcbb0e10eff364.tar.zst
php-shirabe-7d3a88cb55f101f376a6635ea7dcbb0e10eff364.zip
refactor(autoload): drop deprecated Autoload\ClassMapGenerator impl
Composer\Autoload\ClassMapGenerator has been deprecated since Composer 2.4.0 and is no longer referenced by Composer itself, which uses the composer/class-map-generator package directly. Remove its dump/createMap port (and the unwired scanned_files TODO), keeping only the type with a #[deprecated] attribute and a TODO(plugin) note so it can be implemented later for plugins that may still rely on it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe')
-rw-r--r--crates/shirabe/src/autoload/class_map_generator.rs109
1 files changed, 17 insertions, 92 deletions
diff --git a/crates/shirabe/src/autoload/class_map_generator.rs b/crates/shirabe/src/autoload/class_map_generator.rs
index 6aa6492..06dc34d 100644
--- a/crates/shirabe/src/autoload/class_map_generator.rs
+++ b/crates/shirabe/src/autoload/class_map_generator.rs
@@ -1,96 +1,21 @@
//! ref: composer/src/Composer/Autoload/ClassMapGenerator.php
-use indexmap::IndexMap;
-
-use shirabe_class_map_generator::class_map_generator::ClassMapGenerator as ExternalClassMapGenerator;
-use shirabe_php_shim::PhpMixed;
-
-use crate::io::IOInterface;
-use crate::io::IOInterfaceImmutable;
-
+/// `Composer\Autoload\ClassMapGenerator`.
+///
+/// Deprecated since Composer 2.4.0 in favor of the composer/class-map-generator
+/// package (`shirabe-class-map-generator`), which Composer itself now uses
+/// directly. Composer's own code no longer references this class, so its
+/// `dump` / `createMap` methods are intentionally left unported.
+///
+/// Even though it is deprecated, plugins may still use it, so this type will
+/// eventually have to be implemented alongside plugin API support. It is left
+/// here intentionally so that implementation is not forgotten.
+///
+/// TODO(plugin): implement `dump` / `createMap` for plugins still relying on
+/// this deprecated class.
#[derive(Debug)]
+#[deprecated(
+ since = "Composer 2.4.0",
+ note = "use the composer/class-map-generator package (shirabe-class-map-generator) instead"
+)]
pub struct ClassMapGenerator;
-
-impl ClassMapGenerator {
- pub fn dump(dirs: Vec<String>, file: &str) -> anyhow::Result<()> {
- let mut maps: IndexMap<String, String> = IndexMap::new();
- for dir in dirs {
- maps.extend(ClassMapGenerator::create_map(
- PhpMixed::String(dir),
- None,
- None,
- None,
- None,
- &mut IndexMap::new(),
- )?);
- }
- let maps_php = PhpMixed::Array(
- maps.into_iter()
- .map(|(k, v)| (k, Box::new(PhpMixed::String(v))))
- .collect(),
- );
- std::fs::write(
- file,
- format!(
- "<?php return {};",
- shirabe_php_shim::var_export(&maps_php, true)
- ),
- )?;
- Ok(())
- }
-
- pub fn create_map(
- path: PhpMixed,
- excluded: Option<String>,
- mut io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>,
- namespace: Option<String>,
- autoload_type: Option<String>,
- scanned_files: &mut IndexMap<String, bool>,
- ) -> anyhow::Result<IndexMap<String, String>> {
- let _ = scanned_files;
- let mut generator = ExternalClassMapGenerator::new(vec![
- "php".to_string(),
- "inc".to_string(),
- "hh".to_string(),
- ]);
- // TODO(phase-b): scanned_files tracking via avoid_duplicate_scans not wired up
- generator.avoid_duplicate_scans(None);
-
- generator.scan_paths(
- path,
- excluded,
- autoload_type.as_deref().unwrap_or("classmap"),
- namespace,
- vec![],
- )?;
-
- let class_map = generator.get_class_map();
-
- if let Some(io) = io.as_mut() {
- for msg in class_map.get_psr_violations() {
- io.write_error(&format!("<warning>{}</warning>", msg));
- }
-
- for (class, paths) in class_map.get_ambiguous_classes(None)? {
- if paths.len() > 1 {
- io.write_error(&format!(
- "<warning>Warning: Ambiguous class resolution, \"{}\" was found {}x: in \"{}\" and \"{}\", the first will be used.</warning>",
- class,
- paths.len() + 1,
- class_map.get_class_path(&class).unwrap_or(""),
- paths.join("\", \""),
- ));
- } else {
- io.write_error(&format!(
- "<warning>Warning: Ambiguous class resolution, \"{}\" was found in both \"{}\" and \"{}\", the first will be used.</warning>",
- class,
- class_map.get_class_path(&class).unwrap_or(""),
- paths.join("\", \""),
- ));
- }
- }
- }
-
- Ok(class_map.get_map().clone())
- }
-}