From 3a388b98a9aa6a14b1c7f7dc909c109cf9837800 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 00:59:54 +0900 Subject: refactor: narrow pub(crate) items to private Porting mapped every PHP `protected` member onto `pub(crate)`, which is wider than nearly all of them need. Each item demoted here is reached only from the module that defines it, so the crate-wide visibility conveyed nothing. Every `pub(crate)` that survives has at least one reader in another module of the same crate. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/command/base_command.rs | 10 +++---- crates/shirabe/src/command/config_command.rs | 13 ++++----- .../shirabe/src/command/create_project_command.rs | 2 +- crates/shirabe/src/command/diagnose_command.rs | 8 ++--- crates/shirabe/src/command/init_command.rs | 13 ++++----- crates/shirabe/src/command/show_command.rs | 34 +++++++++++----------- 6 files changed, 37 insertions(+), 43 deletions(-) (limited to 'crates/shirabe/src/command') diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs index 9eb28dd8..d7f935c1 100644 --- a/crates/shirabe/src/command/base_command.rs +++ b/crates/shirabe/src/command/base_command.rs @@ -38,16 +38,16 @@ pub const INVALID: i64 = 2; #[derive(Debug)] pub struct BaseCommandData { inner: CommandData, - pub(crate) composer: std::cell::RefCell>, - pub(crate) io: std::cell::RefCell>>>, + composer: std::cell::RefCell>, + io: std::cell::RefCell>>>, /// The definition entries that were registered through the Composer-typed /// InputArgument/InputOption (which carry the suggested-values backport). PHP checks /// `$definition->getArgument($name) instanceof Composer\Console\Input\InputArgument`; in /// this port `set_definition` converts the entries to the Symfony types for storage, so /// the Composer-typedness is tracked by name in these side maps instead. - pub(crate) composer_arguments: + composer_arguments: std::cell::RefCell>>, - pub(crate) composer_options: + composer_options: std::cell::RefCell>>, } @@ -65,7 +65,7 @@ impl BaseCommandData { /// Access to the embedded Symfony command state, used by the Composer-typed definition /// builders to forward to `CommandData`'s Symfony-typed entry points. `CommandData` is /// interior-mutable, so a shared reference is enough. - pub(crate) fn command_data(&self) -> &CommandData { + fn command_data(&self) -> &CommandData { &self.inner } } diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index 3d92de4b..504a0f11 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -38,16 +38,15 @@ pub struct ConfigCommand { config_file: std::cell::RefCell>>>, config_source: std::cell::RefCell>, - pub(crate) auth_config_file: - std::cell::RefCell>>>, - pub(crate) auth_config_source: std::cell::RefCell>, + auth_config_file: std::cell::RefCell>>>, + auth_config_source: std::cell::RefCell>, } impl_php_class!(ConfigCommand, r"Composer\Command\ConfigCommand"); impl ConfigCommand { /// List of additional configurable package-properties - pub(crate) const CONFIGURABLE_PACKAGE_PROPERTIES: &'static [&'static str] = &[ + const CONFIGURABLE_PACKAGE_PROPERTIES: &'static [&'static str] = &[ "name", "type", "description", @@ -77,7 +76,7 @@ impl ConfigCommand { command } - pub(crate) fn handle_single_value( + fn handle_single_value( &self, key: &str, callbacks: &(ValidatorFn, NormalizerFn), @@ -143,7 +142,7 @@ impl ConfigCommand { Ok(()) } - pub(crate) fn handle_multi_value( + fn handle_multi_value( &self, key: &str, callbacks: &(ValidatorFn, NormalizerFn), @@ -181,7 +180,7 @@ impl ConfigCommand { } /// Display the contents of the file in a pretty formatted way - pub(crate) fn list_configuration( + fn list_configuration( &self, contents: PhpMixed, raw_contents: PhpMixed, diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index c7768f11..124f809b 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -56,7 +56,7 @@ pub struct CreateProjectCommand { base_command_data: BaseCommandData, /// @var SuggestedPackagesReporter - pub(crate) suggested_packages_reporter: + suggested_packages_reporter: std::cell::RefCell>>>, } diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 451b051c..4b148c09 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -50,11 +50,9 @@ use shirabe_symfony_process::ExecutableFinder; pub struct DiagnoseCommand { base_command_data: BaseCommandData, - pub(crate) http_downloader: - std::cell::RefCell>>>, - pub(crate) process: - std::cell::RefCell>>>, - pub(crate) exit_code: std::cell::Cell, + http_downloader: std::cell::RefCell>>>, + process: std::cell::RefCell>>>, + exit_code: std::cell::Cell, } impl_php_class!(DiagnoseCommand, r"Composer\Command\DiagnoseCommand"); diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index 7e6021a9..c348fa6f 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -125,10 +125,7 @@ impl InitCommand { .into()) } - pub(crate) fn format_authors( - &self, - author: &str, - ) -> anyhow::Result>> { + fn format_authors(&self, author: &str) -> anyhow::Result>> { let parsed = self.parse_author_string(author)?; let mut author_map: IndexMap = IndexMap::new(); let name = parsed.get("name").cloned().unwrap_or(None); @@ -163,7 +160,7 @@ impl InitCommand { Some(implode("\\", &namespace)) } - pub(crate) fn get_git_config(&self) -> IndexMap { + fn get_git_config(&self) -> IndexMap { if self.git_config.borrow().is_some() { return self.git_config.borrow().clone().unwrap_or_default(); } @@ -208,7 +205,7 @@ impl InitCommand { /// "/$vendor/" /// "/$vendor/*" /// "$vendor/*" - pub(crate) fn has_vendor_ignore(&self, ignore_file: &str, vendor: &str) -> bool { + fn has_vendor_ignore(&self, ignore_file: &str, vendor: &str) -> bool { if !file_exists(ignore_file) { return false; } @@ -225,7 +222,7 @@ impl InitCommand { false } - pub(crate) fn add_vendor_ignore(&self, ignore_file: &str, vendor: &str) { + fn add_vendor_ignore(&self, ignore_file: &str, vendor: &str) { let mut contents = String::new(); if file_exists(ignore_file) { contents = file_get_contents(ignore_file).unwrap_or_default(); @@ -269,7 +266,7 @@ impl InitCommand { self.add_vendor_ignore(ignore_file, vendor) } - pub(crate) fn is_valid_email(&self, email: &str) -> bool { + fn is_valid_email(&self, email: &str) -> bool { shirabe_php_shim::filter_var_email(email) } diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index f2246cbe..ead034da 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -55,8 +55,8 @@ use shirabe_symfony_console::output::OutputInterface; pub struct ShowCommand { base_command_data: BaseCommandData, - pub(crate) version_parser: std::cell::RefCell, - pub(crate) colors: std::cell::RefCell>, + version_parser: std::cell::RefCell, + colors: std::cell::RefCell>, repository_set: std::cell::RefCell>>>, } @@ -83,7 +83,7 @@ impl ShowCommand { } /// PHP: protected function suggestPackageBasedOnMode(): \Closure - pub(crate) fn suggest_package_based_on_mode(&self) -> crate::console::input::SuggestedValues { + fn suggest_package_based_on_mode(&self) -> crate::console::input::SuggestedValues { crate::console::input::SuggestedValues::Closure(Box::new(|this, input, suggestions| { if input.get_option("available")?.to_bool() || input.get_option("all")?.to_bool() { return this.suggest_available_package_incl_platform().call( @@ -259,7 +259,7 @@ impl ShowCommand { } } - pub(crate) fn get_root_requires(&self) -> Vec { + fn get_root_requires(&self) -> Vec { let composer_rc = self.try_composer(None, None); let composer_rc = match composer_rc { None => return vec![], @@ -279,7 +279,7 @@ impl ShowCommand { combined.keys().map(|k| strtolower(k)).collect() } - pub(crate) fn get_version_style( + fn get_version_style( &self, latest_package: PackageInterfaceHandle, package: PackageInterfaceHandle, @@ -294,7 +294,7 @@ impl ShowCommand { } /// finds a package by name and version if provided - pub(crate) fn get_package( + fn get_package( &self, installed_repo: &RepositoryInterfaceHandle, repos: &RepositoryInterfaceHandle, @@ -371,7 +371,7 @@ impl ShowCommand { } /// Prints package info. - pub(crate) fn print_package_info( + fn print_package_info( &self, package: CompletePackageInterfaceHandle, versions: &IndexMap, @@ -401,7 +401,7 @@ impl ShowCommand { } /// Prints package metadata. - pub(crate) fn print_meta( + fn print_meta( &self, package: CompletePackageInterfaceHandle, versions: &IndexMap, @@ -564,7 +564,7 @@ impl ShowCommand { } /// Prints all available versions of this package and highlights the installed one if any. - pub(crate) fn print_versions( + fn print_versions( &self, package: CompletePackageInterfaceHandle, versions: &IndexMap, @@ -599,7 +599,7 @@ impl ShowCommand { } /// print link objects - pub(crate) fn print_links( + fn print_links( &self, package: CompletePackageInterfaceHandle, link_type: &str, @@ -622,7 +622,7 @@ impl ShowCommand { } /// Prints the licenses of a package with metadata - pub(crate) fn print_licenses(&self, package: CompletePackageInterfaceHandle) { + fn print_licenses(&self, package: CompletePackageInterfaceHandle) { let spdx_licenses = SpdxLicenses::new(); let licenses = package.get_license(); @@ -650,7 +650,7 @@ impl ShowCommand { } /// Prints package info in JSON format. - pub(crate) fn print_package_info_as_json( + fn print_package_info_as_json( &self, package: CompletePackageInterfaceHandle, versions: &IndexMap, @@ -971,7 +971,7 @@ impl ShowCommand { } /// Init styles for tree - pub(crate) fn init_styles(&self, output: std::rc::Rc>) { + fn init_styles(&self, output: std::rc::Rc>) { *self.colors.borrow_mut() = vec![ "green".to_string(), "yellow".to_string(), @@ -991,7 +991,7 @@ impl ShowCommand { } /// Display the tree - pub(crate) fn display_package_tree(&self, array_tree: Vec>) { + fn display_package_tree(&self, array_tree: Vec>) { for package in array_tree.iter() { let name = package .get("name") @@ -1070,7 +1070,7 @@ impl ShowCommand { } /// Generate the package tree - pub(crate) fn generate_package_tree( + fn generate_package_tree( &self, package: PackageInterfaceHandle, installed_repo: &RepositoryInterfaceHandle, @@ -1147,7 +1147,7 @@ impl ShowCommand { } /// Display a package tree - pub(crate) fn display_tree( + fn display_tree( &self, package: &PhpMixed, packages_in_tree: &[PhpMixed], @@ -1216,7 +1216,7 @@ impl ShowCommand { } /// Display a package tree - pub(crate) fn add_tree( + fn add_tree( &self, name: &str, link: &Link, -- cgit v1.3.1-4-g156e