diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 17:02:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 17:12:37 +0900 |
| commit | 84fe6ac6977f15cbec85cbc9f773567742a7fb87 (patch) | |
| tree | 5701e7c980585dd404471ab9fa53e98a0ba601ab /crates/shirabe-external-packages/src/symfony/console | |
| parent | 12a7756588a20f1351e6976f0c009de5992514a9 (diff) | |
| download | php-shirabe-84fe6ac6977f15cbec85cbc9f773567742a7fb87.tar.gz php-shirabe-84fe6ac6977f15cbec85cbc9f773567742a7fb87.tar.zst php-shirabe-84fe6ac6977f15cbec85cbc9f773567742a7fb87.zip | |
refactor(math): use method-style max/min/clamp over std::cmp
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console')
5 files changed, 24 insertions, 28 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs index 421cf52..097d7f4 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs @@ -529,7 +529,7 @@ impl TextDescriptor { for option in options { // "-" + shortcut + ", --" + name let mut name_length = 1 - + std::cmp::max(Helper::width(option.get_shortcut().unwrap_or("")), 1) + + Helper::width(option.get_shortcut().unwrap_or("")).max(1) + 4 + Helper::width(option.get_name()); if option.is_negatable() { diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs index d9b808e..d9d3fd6 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs @@ -225,11 +225,10 @@ impl ProgressBar { } pub fn get_bar_offset(&self) -> f64 { - shirabe_php_shim::floor(if self.max != 0 { + f64::floor(if self.max != 0 { self.percent * self.bar_width as f64 } else if self.redraw_freq.is_none() { - ((shirabe_php_shim::min(5, self.bar_width / 15) * self.write_count) % self.bar_width) - as f64 + (((self.bar_width / 15).min(5) * self.write_count) % self.bar_width) as f64 } else { (self.step % self.bar_width) as f64 }) @@ -260,7 +259,7 @@ impl ProgressBar { } pub fn set_bar_width(&mut self, size: i64) { - self.bar_width = shirabe_php_shim::max(1, size); + self.bar_width = size.max(1); } pub fn get_bar_width(&self) -> i64 { @@ -309,7 +308,7 @@ impl ProgressBar { /// /// `$freq` The frequency in steps pub fn set_redraw_frequency(&mut self, freq: Option<i64>) { - self.redraw_freq = freq.map(|freq| shirabe_php_shim::max(1, freq)); + self.redraw_freq = freq.map(|freq| freq.max(1)); } pub fn min_seconds_between_redraws(&mut self, seconds: f64) { @@ -416,7 +415,7 @@ impl ProgressBar { pub fn set_max_steps(&mut self, max: i64) { self.format = None; - self.max = shirabe_php_shim::max(0, max); + self.max = max.max(0); self.step_width = if self.max != 0 { Helper::width(&self.max.to_string()) } else { @@ -512,9 +511,9 @@ impl ProgressBar { message_line, )); if message_line_length > self.terminal.get_width() { - line_count += shirabe_php_shim::floor( - message_line_length as f64 / self.terminal.get_width() as f64, - ) as i64; + line_count += (message_line_length as f64 + / self.terminal.get_width() as f64) + .floor() as i64; } } todo!("$this->output->clear($lineCount); (ConsoleSectionOutput)"); @@ -699,7 +698,7 @@ impl ProgressBar { Box::new( |bar: &ProgressBar, _output: &Rc<RefCell<dyn OutputInterface>>| { Ok(Ok(shirabe_php_shim::PhpMixed::Float( - shirabe_php_shim::floor(bar.get_progress_percent() * 100.0), + (bar.get_progress_percent() * 100.0).floor(), ))) }, ), diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs index 678831a..9c868c4 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs @@ -558,7 +558,7 @@ impl Table { ); } - let title_start = shirabe_php_shim::intdiv(markup_length - title_length, 2); + let title_start = (markup_length - title_length) / 2; if shirabe_php_shim::mb_detect_encoding(&markup, None, true).is_none() { markup = shirabe_php_shim::substr_replace( &markup, @@ -1087,9 +1087,8 @@ impl Table { if text_length > 0 { let content_columns = shirabe_php_shim::mb_str_split( &text_content, - shirabe_php_shim::ceil( - text_length as f64 / Self::cell_colspan(&cell) as f64, - ) as i64, + (text_length as f64 / Self::cell_colspan(&cell) as f64).ceil() + as i64, ); for (position, content) in content_columns.into_iter().enumerate() { Self::vec_set( diff --git a/crates/shirabe-external-packages/src/symfony/console/output/console_section_output.rs b/crates/shirabe-external-packages/src/symfony/console/output/console_section_output.rs index d05d0a4..3120775 100644 --- a/crates/shirabe-external-packages/src/symfony/console/output/console_section_output.rs +++ b/crates/shirabe-external-packages/src/symfony/console/output/console_section_output.rs @@ -92,9 +92,9 @@ impl ConsoleSectionOutput { /// @internal pub fn add_content(&self, input: &str) { for line_content in shirabe_php_shim::explode(shirabe_php_shim::PHP_EOL, input) { - let count = shirabe_php_shim::ceil( - self.get_display_length(&line_content) as f64 / self.terminal.get_width() as f64, - ); + let count = (self.get_display_length(&line_content) as f64 + / self.terminal.get_width() as f64) + .ceil(); self.lines .set(self.lines.get() + if count != 0.0 { count as i64 } else { 1 }); self.content.borrow_mut().push(line_content); diff --git a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs index ce08f45..83229a9 100644 --- a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs +++ b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs @@ -61,7 +61,7 @@ impl SymfonyStyle { let w = Terminal::new().get_width(); if w != 0 { w } else { MAX_LINE_LENGTH } }; - let line_length = shirabe_php_shim::min( + let line_length = std::cmp::min( width - (std::path::MAIN_SEPARATOR == '\\') as i64, MAX_LINE_LENGTH, ); @@ -350,7 +350,7 @@ impl SymfonyStyle { &mut *self.get_formatter().borrow_mut(), &message, )); - let message_line_length = shirabe_php_shim::min( + let message_line_length = std::cmp::min( self.line_length - prefix_length - indent_length + decoration_length, self.line_length, ); @@ -392,14 +392,12 @@ impl SymfonyStyle { *line = format!("{}{}", prefix, line); line.push_str(&shirabe_php_shim::str_repeat( " ", - shirabe_php_shim::max( - self.line_length - - Helper::width(&Helper::remove_decoration( - &mut *self.output.borrow().get_formatter().borrow_mut(), - line, - )), - 0, - ) as usize, + (self.line_length + - Helper::width(&Helper::remove_decoration( + &mut *self.output.borrow().get_formatter().borrow_mut(), + line, + ))) + .max(0) as usize, )); if let Some(style) = style { |
