From 54760d5c73ca20de2e155df274d576cec9ea0ed0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 10 Aug 2026 02:48:46 +0900 Subject: style(php-shim): drop the underscore from used parameter names These parameters kept the leading underscore they were given while their function bodies were still todo!(), and the underscore now reads as "this argument is ignored" for arguments the bodies do use. Removing the prefix stops it from suppressing four clippy lints, fixed alongside: one redundant field name, and three `&mut Vec` parameters that only need a slice. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-shim/src/fs.rs | 115 ++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 60 deletions(-) (limited to 'crates/shirabe-php-shim/src/fs.rs') diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs index c2b0dc41..a948a6f2 100644 --- a/crates/shirabe-php-shim/src/fs.rs +++ b/crates/shirabe-php-shim/src/fs.rs @@ -205,28 +205,25 @@ impl RecursiveIteratorFileInfo { } pub fn recursive_directory_iterator( - _path: impl AsRef, - _flags: i64, + path: impl AsRef, + flags: i64, ) -> Result { - let root = _path.as_ref().to_path_buf(); + let root = path.as_ref().to_path_buf(); if !root.is_dir() { return Err(UnexpectedValueException::new(format!( "RecursiveDirectoryIterator::__construct({}): Failed to open directory", root.display() ))); } - Ok(RecursiveDirectoryIterator { - root, - flags: _flags, - }) + Ok(RecursiveDirectoryIterator { root, flags }) } pub fn recursive_iterator_iterator( - _iter: RecursiveDirectoryIterator, - _mode: i64, + iter: RecursiveDirectoryIterator, + mode: i64, ) -> RecursiveIteratorIterator { let mut entries = Vec::new(); - rii_walk(&_iter.root, &_iter.root, _iter.flags, _mode, &mut entries); + rii_walk(&iter.root, &iter.root, iter.flags, mode, &mut entries); RecursiveIteratorIterator { entries, cursor: std::cell::Cell::new(0), @@ -712,9 +709,9 @@ pub fn fflush(stream: &PhpResource) -> bool { } } -pub fn lstat(_filename: impl AsRef) -> Option> { +pub fn lstat(filename: impl AsRef) -> Option> { use std::os::unix::fs::MetadataExt; - let m = std::fs::symlink_metadata(_filename).ok()?; + let m = std::fs::symlink_metadata(filename).ok()?; Some(stat_fields_map([ ("dev", m.dev() as i64), ("ino", m.ino() as i64), @@ -789,16 +786,16 @@ pub fn touch3(path: impl AsRef, mtime: i64, atime: i64) -> bool touch_impl(path.as_ref(), mtime, atime) } -pub fn chmod(_path: impl AsRef, _mode: u32) -> bool { +pub fn chmod(path: impl AsRef, mode: u32) -> bool { use std::os::unix::fs::PermissionsExt; - std::fs::set_permissions(_path.as_ref(), std::fs::Permissions::from_mode(_mode)).is_ok() + std::fs::set_permissions(path.as_ref(), std::fs::Permissions::from_mode(mode)).is_ok() } -pub fn fileperms(_path: impl AsRef) -> i64 { +pub fn fileperms(path: impl AsRef) -> i64 { use std::os::unix::fs::MetadataExt; // PHP returns the full st_mode (file type bits included). // TODO(phase-c): PHP returns false on error; this i64 signature reports 0 instead. - std::fs::metadata(_path.as_ref()) + std::fs::metadata(path.as_ref()) .map(|m| m.mode() as i64) .unwrap_or(0) } @@ -811,12 +808,12 @@ pub fn file_exists(path: impl AsRef) -> bool { path.as_ref().exists() } -pub fn is_writable(_path: impl AsRef) -> bool { - nix::unistd::access(_path.as_ref(), nix::unistd::AccessFlags::W_OK).is_ok() +pub fn is_writable(path: impl AsRef) -> bool { + nix::unistd::access(path.as_ref(), nix::unistd::AccessFlags::W_OK).is_ok() } -pub fn is_readable(_path: impl AsRef) -> bool { - let path = _path.as_ref(); +pub fn is_readable(path: impl AsRef) -> bool { + let path = path.as_ref(); match std::fs::metadata(path) { Ok(meta) => { if meta.is_dir() { @@ -829,8 +826,8 @@ pub fn is_readable(_path: impl AsRef) -> bool { } } -pub fn is_executable(_path: impl AsRef) -> bool { - nix::unistd::access(_path.as_ref(), nix::unistd::AccessFlags::X_OK).is_ok() +pub fn is_executable(path: impl AsRef) -> bool { + nix::unistd::access(path.as_ref(), nix::unistd::AccessFlags::X_OK).is_ok() } pub fn is_file(path: impl AsRef) -> bool { @@ -856,16 +853,16 @@ pub fn readlink(path: impl AsRef) -> Option { .map(|target| target.to_string_lossy().into_owned()) } -pub fn fileatime(_filename: impl AsRef) -> Option { - std::fs::metadata(_filename.as_ref()) +pub fn fileatime(filename: impl AsRef) -> Option { + std::fs::metadata(filename.as_ref()) .ok() .and_then(|m| m.accessed().ok()) .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()) .map(|d| d.as_secs() as i64) } -pub fn filemtime(_filename: impl AsRef) -> Option { - std::fs::metadata(_filename.as_ref()) +pub fn filemtime(filename: impl AsRef) -> Option { + std::fs::metadata(filename.as_ref()) .ok() .and_then(|m| m.modified().ok()) .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()) @@ -876,21 +873,19 @@ pub fn unlink(path: impl AsRef) -> Result<(), std::io::Error> { std::fs::remove_file(path) } -pub fn unlink_silent(_path: impl AsRef) -> bool { +pub fn unlink_silent(path: impl AsRef) -> bool { // PHP's `@unlink`: delete the file, suppressing any warning. - std::fs::remove_file(_path.as_ref()).is_ok() + std::fs::remove_file(path.as_ref()).is_ok() } -pub fn file_put_contents(_path: &str, _data: &[u8]) -> Option { - std::fs::write(_path, _data) - .ok() - .map(|_| _data.len() as i64) +pub fn file_put_contents(path: &str, data: &[u8]) -> Option { + std::fs::write(path, data).ok().map(|_| data.len() as i64) } -pub fn file_put_contents3(_filename: &str, _data: &str, _flags: i64) -> Option { +pub fn file_put_contents3(filename: &str, data: &str, flags: i64) -> Option { // TODO(phase-c): the LOCK_EX and FILE_USE_INCLUDE_PATH flags are ignored; only FILE_APPEND is // honored. - let append = _flags & FILE_APPEND != 0; + let append = flags & FILE_APPEND != 0; let mut opts = std::fs::OpenOptions::new(); opts.write(true).create(true); if append { @@ -898,9 +893,9 @@ pub fn file_put_contents3(_filename: &str, _data: &str, _flags: i64) -> Option) -> Option { @@ -916,25 +911,25 @@ pub fn file_get_contents(path: impl AsRef) -> Option { } pub fn file_get_contents5( - _path: &str, + path: &str, _use_include_path: bool, _context: PhpMixed, - _offset: i64, - _length: Option, + offset: i64, + length: Option, ) -> Option { // TODO(phase-c): the stream $context and FILE_USE_INCLUDE_PATH are ignored; only $offset and // $length are applied (to the file read from the local filesystem). // PHP supports the file:// stream wrapper; strip it to read the local file. - let path = _path.strip_prefix("file://").unwrap_or(_path); + let path = path.strip_prefix("file://").unwrap_or(path); let bytes = std::fs::read(path).ok()?; let len = bytes.len() as i64; - let start = if _offset < 0 { - (len + _offset).max(0) + let start = if offset < 0 { + (len + offset).max(0) } else { - _offset.min(len) + offset.min(len) } as usize; let slice = &bytes[start..]; - let slice = match _length { + let slice = match length { Some(l) if l >= 0 => &slice[..(l as usize).min(slice.len())], _ => slice, }; @@ -947,21 +942,21 @@ pub fn getcwd() -> Option { .map(|p| p.to_string_lossy().into_owned()) } -pub fn chdir(_path: impl AsRef) -> anyhow::Result<()> { - Ok(std::env::set_current_dir(_path.as_ref())?) +pub fn chdir(path: impl AsRef) -> anyhow::Result<()> { + Ok(std::env::set_current_dir(path.as_ref())?) } -pub fn glob(_pattern: &str) -> Vec { - glob_with_flags(_pattern, 0) +pub fn glob(pattern: &str) -> Vec { + glob_with_flags(pattern, 0) } pub const FILE_SKIP_EMPTY_LINES: i64 = 4; -pub fn file(_filename: &str, _flags: i64) -> Option> { - let content = std::fs::read(_filename).ok()?; +pub fn file(filename: &str, flags: i64) -> Option> { + let content = std::fs::read(filename).ok()?; let s = String::from_utf8_lossy(&content); - let ignore_newlines = _flags & FILE_IGNORE_NEW_LINES != 0; - let skip_empty = _flags & FILE_SKIP_EMPTY_LINES != 0; + let ignore_newlines = flags & FILE_IGNORE_NEW_LINES != 0; + let skip_empty = flags & FILE_SKIP_EMPTY_LINES != 0; let mut lines = Vec::new(); // PHP keeps the trailing newline on each element unless FILE_IGNORE_NEW_LINES is set. for line in s.split_inclusive('\n') { @@ -1025,8 +1020,8 @@ pub fn rename( std::fs::rename(old_name, new_name).is_ok() } -pub fn copy(_source: impl AsRef, _dest: impl AsRef) -> bool { - std::fs::copy(_source.as_ref(), _dest.as_ref()).is_ok() +pub fn copy(source: impl AsRef, dest: impl AsRef) -> bool { + std::fs::copy(source.as_ref(), dest.as_ref()).is_ok() } pub fn ftruncate(stream: &PhpResource, size: i64) -> bool { @@ -1167,15 +1162,15 @@ pub const GLOB_MARK: i64 = 8; pub const GLOB_ONLYDIR: i64 = 1024; pub const GLOB_BRACE: i64 = 4096; -pub fn glob_with_flags(_pattern: &str, _flags: i64) -> Vec { - let patterns = if _flags & GLOB_BRACE != 0 { - glob_expand_braces(_pattern) +pub fn glob_with_flags(pattern: &str, flags: i64) -> Vec { + let patterns = if flags & GLOB_BRACE != 0 { + glob_expand_braces(pattern) } else { - vec![_pattern.to_string()] + vec![pattern.to_string()] }; let mut results: Vec = Vec::new(); for pattern in patterns { - glob_collect(&pattern, _flags, &mut results); + glob_collect(&pattern, flags, &mut results); } // PHP sorts the result set by default (GLOB_NOSORT is not modeled here). results.sort(); -- cgit v1.3.1-4-g156e