aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 03:08:31 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 03:09:22 +0900
commit25fa6c6b079b100f1c3970662d06d63bd741c1f0 (patch)
treefb564230eb241d11e9616119ae5badc45e8caf30 /crates
parent7d06a493514c20338278c8ffdf0ba2e0f0eed353 (diff)
downloadphp-shirabe-25fa6c6b079b100f1c3970662d06d63bd741c1f0.tar.gz
php-shirabe-25fa6c6b079b100f1c3970662d06d63bd741c1f0.tar.zst
php-shirabe-25fa6c6b079b100f1c3970662d06d63bd741c1f0.zip
refactor(package-discovery): extend BaseCommand as supertrait
PHP's PackageDiscoveryTrait is mixed into classes extending BaseCommand and calls its methods directly. Model that with a supertrait bound so get_io, try_composer, require_composer, get_platform_requirement_filter and normalize_requirements come from BaseCommand instead of being redeclared and delegated per command. Propagate the Result returns at the call sites and drop the now-redundant per-command impls. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe/src/command/init_command.rs31
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs28
-rw-r--r--crates/shirabe/src/command/require_command.rs29
3 files changed, 7 insertions, 81 deletions
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index f345d76..d7beaf8 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -65,35 +65,6 @@ impl PackageDiscoveryTrait for InitCommand {
{
&mut self.repository_sets
}
-
- fn get_io(&self) -> std::rc::Rc<std::cell::RefCell<dyn IOInterface>> {
- todo!()
- }
-
- fn try_composer(&self) -> Option<PartialComposerHandle> {
- todo!()
- }
-
- fn require_composer(
- &self,
- disable_plugins: Option<bool>,
- disable_scripts: Option<bool>,
- ) -> PartialComposerHandle {
- todo!()
- }
-
- fn get_platform_requirement_filter(
- &self,
- input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
- ) -> std::rc::Rc<
- dyn crate::filter::platform_requirement_filter::PlatformRequirementFilterInterface,
- > {
- todo!()
- }
-
- fn normalize_requirements(&self, requires: Vec<String>) -> Vec<IndexMap<String, String>> {
- todo!()
- }
}
impl Default for InitCommand {
@@ -152,7 +123,7 @@ impl Command for InitCommand {
input: Rc<RefCell<dyn InputInterface>>,
output: Rc<RefCell<dyn OutputInterface>>,
) -> anyhow::Result<i64> {
- let io = PackageDiscoveryTrait::get_io(self);
+ let io = self.get_io();
let allowlist: Vec<String> = vec![
"name".to_string(),
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index e2ffa7c..c182645 100644
--- a/crates/shirabe/src/command/package_discovery_trait.rs
+++ b/crates/shirabe/src/command/package_discovery_trait.rs
@@ -15,6 +15,7 @@ use shirabe_php_shim::{
strpos, trim,
};
+use crate::command::BaseCommand;
use crate::composer::PartialComposerHandle;
use crate::factory::Factory;
use crate::filter::platform_requirement_filter::IgnoreAllPlatformRequirementFilter;
@@ -33,7 +34,7 @@ use crate::repository::{RepositoryInterface, SearchResult};
use crate::util::Filesystem;
/// @internal
-pub trait PackageDiscoveryTrait {
+pub trait PackageDiscoveryTrait: BaseCommand {
// PHP: private $repos; private $repositorySets;
// TODO(phase-b): trait fields require an associated state struct in Rust; expose via accessors
fn get_repos_mut(&mut self) -> &mut Option<crate::repository::RepositoryInterfaceHandle>;
@@ -41,23 +42,6 @@ pub trait PackageDiscoveryTrait {
&mut self,
) -> &mut IndexMap<String, std::rc::Rc<std::cell::RefCell<RepositorySet>>>;
- // PHP: trait dependencies (provided by BaseCommand)
- fn get_io(&self) -> std::rc::Rc<std::cell::RefCell<dyn IOInterface>>;
- fn try_composer(&self) -> Option<PartialComposerHandle>;
- fn require_composer(
- &self,
- disable_plugins: Option<bool>,
- disable_scripts: Option<bool>,
- ) -> PartialComposerHandle;
- fn get_platform_requirement_filter(
- &self,
- input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
- ) -> std::rc::Rc<
- dyn crate::filter::platform_requirement_filter::PlatformRequirementFilterInterface,
- >;
-
- fn normalize_requirements(&self, requires: Vec<String>) -> Vec<IndexMap<String, String>>;
-
fn get_repos(&mut self) -> crate::repository::RepositoryInterfaceHandle {
if self.get_repos_mut().is_none() {
// PHP: array_merge([new PlatformRepository], RepositoryFactory::defaultReposWithDefaultManager($this->getIO()))
@@ -160,7 +144,7 @@ pub trait PackageDiscoveryTrait {
fixed: bool,
) -> Result<Vec<String>> {
if !requires.is_empty() {
- let requires_norm = self.normalize_requirements(requires.clone());
+ let requires_norm = self.normalize_requirements(requires.clone())?;
let mut result: Vec<String> = vec![];
let io = self.get_io();
@@ -228,7 +212,7 @@ pub trait PackageDiscoveryTrait {
let version_parser = VersionParser::new();
// Collect existing packages
- let composer = self.try_composer();
+ let composer = self.try_composer(None, None);
let composer_ref = composer.as_ref().map(|c| c.borrow_partial());
let repository_manager = composer_ref
.as_ref()
@@ -491,7 +475,7 @@ pub trait PackageDiscoveryTrait {
let platform_requirement_filter = if input.borrow().has_option("ignore-platform-reqs")
&& input.borrow().has_option("ignore-platform-req")
{
- self.get_platform_requirement_filter(input.clone())
+ self.get_platform_requirement_filter(input.clone())?
} else {
PlatformRequirementFilterFactory::ignore_nothing()
};
@@ -803,7 +787,7 @@ pub trait PackageDiscoveryTrait {
};
let mut similar_packages: IndexMap<String, i64> = IndexMap::new();
- let composer_for_installed = self.require_composer(None, None);
+ let composer_for_installed = self.require_composer(None, None)?;
let composer_for_installed = composer_for_installed.borrow_partial();
let repository_manager = composer_for_installed.get_repository_manager().clone();
let repository_manager = repository_manager.borrow();
diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs
index 3d8331b..a29f60d 100644
--- a/crates/shirabe/src/command/require_command.rs
+++ b/crates/shirabe/src/command/require_command.rs
@@ -107,35 +107,6 @@ impl PackageDiscoveryTrait for RequireCommand {
) -> &mut IndexMap<String, std::rc::Rc<std::cell::RefCell<RepositorySet>>> {
&mut self.repository_sets
}
-
- fn get_io(&self) -> std::rc::Rc<std::cell::RefCell<dyn IOInterface>> {
- todo!()
- }
-
- fn try_composer(&self) -> Option<PartialComposerHandle> {
- todo!()
- }
-
- fn require_composer(
- &self,
- disable_plugins: Option<bool>,
- disable_scripts: Option<bool>,
- ) -> PartialComposerHandle {
- todo!()
- }
-
- fn get_platform_requirement_filter(
- &self,
- input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
- ) -> std::rc::Rc<
- dyn crate::filter::platform_requirement_filter::PlatformRequirementFilterInterface,
- > {
- todo!()
- }
-
- fn normalize_requirements(&self, requires: Vec<String>) -> Vec<IndexMap<String, String>> {
- todo!()
- }
}
impl Command for RequireCommand {