From 318ea948f5932dfa7942081a269d62fd7161a9bf Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 8 Jun 2026 01:54:56 +0900 Subject: feat(phase-c): resolve reflection/downcast phase-b TODOs Resolve category F phase-b TODOs (class-string, instanceof, get_class, method_exists, __FILE__, Reflection API, downcast). - VcsRepository: dispatch drivers through a VcsDriverKind enum (instantiate/supports/php_class_name) and add constructors to the concrete VCS drivers - repository downcasts via RepositoryInterfaceHandle::downcast_rc and as_any (init/show commands, vcs ValidatingArrayLoader) - BaseCommand::is_self_update_command override replaces an instanceof - Factory::create narrows PartialComposer to ComposerHandle via as_full - InstalledVersions gains set_self_dir/set_installed_is_local_dir, replacing Reflection-based static property mutation - ClassLoader::as_array_iter ports the PHP (array) cast - drop the unnecessary __FILE__ phar branch in self-update application get_class(command) reclassified TODO(plugin); buffer_io StreamableInputInterface downcast and the ValidatingArrayLoader trait redesign left as tracked TODOs. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/factory.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'crates/shirabe/src/factory.rs') diff --git a/crates/shirabe/src/factory.rs b/crates/shirabe/src/factory.rs index ac7c055..c9de808 100644 --- a/crates/shirabe/src/factory.rs +++ b/crates/shirabe/src/factory.rs @@ -15,7 +15,7 @@ use shirabe_php_shim::{ use crate::autoload::AutoloadGenerator; use crate::cache::Cache; -use crate::composer::{ComposerWeakHandle, PartialOrFullComposer}; +use crate::composer::{ComposerHandle, ComposerWeakHandle, PartialOrFullComposer}; use crate::composer::{PartialComposerHandle, PartialComposerWeakHandle}; use crate::config::Config; use crate::config::JsonConfigSource; @@ -1262,7 +1262,7 @@ impl Factory { config: Option, disable_plugins: DisablePlugins, disable_scripts: bool, - ) -> anyhow::Result { + ) -> anyhow::Result { let factory = Self; // for BC reasons, if a config is passed in either as array or a path that is not the default composer.json path @@ -1285,14 +1285,13 @@ impl Factory { let composer = factory.create_composer(io, config, disable_plugins, None, true, disable_scripts)?; - if !composer.is_full() { - // TODO(phase-b): unreachable when fullLoad=true; downcasting needs design. - return Err(anyhow::anyhow!(RuntimeException { + // fullLoad=true guarantees a full Composer; narrow PartialComposer -> Composer (PHP `: Composer`). + composer.as_full().ok_or_else(|| { + anyhow::anyhow!(RuntimeException { message: "Composer expected with fullLoad=true".to_string(), code: 0, - })); - } - Ok(composer) + }) + }) } /// If you are calling this in a plugin, you probably should instead use `$composer->getLoop()->getHttpDownloader()` -- cgit v1.3.1