aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-25 12:16:25 +0900
committernsfisis <nsfisis@gmail.com>2026-07-25 12:16:25 +0900
commit42b5f9e321c918cef542c120ad21ba8a7339eb29 (patch)
tree39f2b5a3cb856de9068f72fb670d170c09a2438f /crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
parentf93d9b49382c8f79fcea4f03361d50bda534bcc4 (diff)
downloadphp-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.tar.gz
php-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.tar.zst
php-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.zip
refactor(operation): replace OperationInterface with AnyOperation enum
Operations are only ever constructed by the dependency resolver, so a plugin has no way to inject an implementation of its own and the set is closed. Modelling it as an enum, like AnyPackage, removes the OperationInterface trait together with its two parallel downcast mechanisms (as_any() + downcast_ref, and as_*_operation()) and the get_package() default method that panicked on UpdateOperation. The PHP idiom `$op instanceof UpdateOperation ? getTargetPackage() : getPackage()`, written out at six call sites, becomes AnyOperation::get_target_package(). InstallationManager's three blocks that matched on the type string and then recovered the type with expect() collapse into exhaustive matches. SolverOperation keeps only its TYPE constant; the shared getOperationType()/__toString() implementations move to AnyOperation, which also drops the five Self::TYPE.to_string() allocations. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs')
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs29
1 files changed, 5 insertions, 24 deletions
diff --git a/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs b/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
index d2dd6651..2fd35af5 100644
--- a/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
+++ b/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
@@ -1,10 +1,9 @@
//! ref: composer/src/Composer/DependencyResolver/Operation/UninstallOperation.php
-use crate::dependency_resolver::operation::OperationInterface;
use crate::dependency_resolver::operation::SolverOperation;
use crate::package::PackageInterfaceHandle;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct UninstallOperation {
pub(crate) package: PackageInterfaceHandle,
}
@@ -18,6 +17,10 @@ impl UninstallOperation {
self.package.clone()
}
+ pub fn show(&self, lock: bool) -> String {
+ Self::format(self.package.clone(), lock)
+ }
+
pub fn format(package: PackageInterfaceHandle, _lock: bool) -> String {
format!(
"Removing <info>{}</info> (<comment>{}</comment>)",
@@ -31,28 +34,6 @@ impl SolverOperation for UninstallOperation {
const TYPE: &'static str = "uninstall";
}
-impl OperationInterface for UninstallOperation {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
- fn get_operation_type(&self) -> String {
- Self::TYPE.to_string()
- }
-
- fn show(&self, lock: bool) -> String {
- Self::format(self.package.clone(), lock)
- }
-
- fn as_uninstall_operation(&self) -> Option<&UninstallOperation> {
- Some(self)
- }
-
- fn get_package(&self) -> PackageInterfaceHandle {
- self.package.clone()
- }
-}
-
impl std::fmt::Display for UninstallOperation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.show(false))