diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-26 01:55:03 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-26 01:55:03 +0900 |
| commit | cbb5118318706dc023eb8551b1f2628f395a6228 (patch) | |
| tree | 35c86c3191c2bfdb154fdfae7ad6f3292c0261f8 /crates/shirabe/src/command | |
| parent | 939359f13acfe8dbf4f16dac517fcbd67d46f611 (diff) | |
| download | php-shirabe-cbb5118318706dc023eb8551b1f2628f395a6228.tar.gz php-shirabe-cbb5118318706dc023eb8551b1f2628f395a6228.tar.zst php-shirabe-cbb5118318706dc023eb8551b1f2628f395a6228.zip | |
refactor(symfony-table): model rows/cells with enums instead of PhpMixed
The Table helper modeled a row's cells as PhpMixed and recovered the concrete
TableCell/TableSeparator types via runtime instance_of, leaving the entire
mixed/array bridge (to_row_vec, cell_colspan, row_get, ...) as todo!(). Replace
that with proper Row/Cell enums:
Row = HeaderDivider | Separator(TableSeparator) | Cells(Vec<Cell>)
Cell = Null | Value(String) | Cell(TableCell) | Separator(TableSeparator)
The internal header/body boundary that PHP detects by object identity
($divider === $row) becomes the dedicated Row::HeaderDivider variant. Style
arguments (PHP string|TableStyle) become a StyleName enum, so Table::new no
longer panics in resolve_style's instance_of stub; TableStyle derives Clone so
named styles resolve from the registry.
PhpMixed-based callers (SymfonyStyle::table, render_table, auditor's sanitize)
bridge via From<PhpMixed> for Cell/Row at the boundary.
Un-ignores LicensesCommandTest text-format cases (4) and
BaseDependencyCommandTest::why; output matches PHP exactly. Removes ~15 impl
todo!()s in the Table helper.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command')
| -rw-r--r-- | crates/shirabe/src/command/base_command.rs | 11 | ||||
| -rw-r--r-- | crates/shirabe/src/command/licenses_command.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/command/update_command.rs | 4 |
3 files changed, 16 insertions, 9 deletions
diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs index 8b6cc20..f754d0a 100644 --- a/crates/shirabe/src/command/base_command.rs +++ b/crates/shirabe/src/command/base_command.rs @@ -579,10 +579,17 @@ impl BaseCommand for BaseCommandData { fn render_table(&self, table: Vec<PhpMixed>, output: Rc<RefCell<dyn OutputInterface>>) { let mut renderer = Table::new(output); renderer - .set_style(PhpMixed::from("compact")) + .set_style("compact".into()) .expect("Table::set_style I/O cannot fail") .expect("'compact' is a built-in table style"); - renderer.set_rows(table).render(); + renderer + .set_rows( + table + .into_iter() + .map(Into::into) + .collect(), + ) + .render(); let _ = TableSeparator::new(); } diff --git a/crates/shirabe/src/command/licenses_command.rs b/crates/shirabe/src/command/licenses_command.rs index 3be4df3..e8d62cc 100644 --- a/crates/shirabe/src/command/licenses_command.rs +++ b/crates/shirabe/src/command/licenses_command.rs @@ -200,11 +200,11 @@ impl Command for LicensesCommand { io.write(""); let mut table = Table::new(output); - table.set_style(shirabe_php_shim::PhpMixed::from("compact"))??; + table.set_style("compact".into())??; table.set_headers(vec![ - PhpMixed::String("Name".to_string()), - PhpMixed::String("Version".to_string()), - PhpMixed::String("Licenses".to_string()), + "Name".into(), + "Version".into(), + "Licenses".into(), ]); for package in &packages { let link = PackageInfo::get_view_source_or_homepage_url(package.clone()); @@ -234,7 +234,7 @@ impl Command for LicensesCommand { crate::package::DisplayMode::SourceRefIfDev, )), PhpMixed::String(licenses_str), - ])); + ]).into()); } table.render(); } diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs index 1903dec..c6c05ba 100644 --- a/crates/shirabe/src/command/update_command.rs +++ b/crates/shirabe/src/command/update_command.rs @@ -698,9 +698,9 @@ impl UpdateCommand { }; let mut table = Table::new(output); - table.set_headers(vec![PhpMixed::String("Selected packages".to_string())]); + table.set_headers(vec!["Selected packages".into()]); for package in &packages { - table.add_row(PhpMixed::List(vec![PhpMixed::String(package.clone())])); + table.add_row(PhpMixed::List(vec![PhpMixed::String(package.clone())]).into()); } table.render(); |
