Normalize Windows temp dir in Given a directory step#330
Normalize Windows temp dir in Given a directory step#330swissspidy wants to merge 1 commit intomainfrom
Given a directory step#330Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the directory validation logic in GivenStepDefinitions.php to better handle system temporary directories across different operating systems, including Mac OS X path prefixes and Windows case-insensitivity. The feedback suggests simplifying the repetitive path comparison logic by using a loop and a dynamic comparison function to improve readability and maintainability.
| $in_temp = 0 === ( $is_windows ? stripos( $dir, $temp_dir_original ) : strpos( $dir, $temp_dir_original ) ) | ||
| || 0 === ( $is_windows ? stripos( $dir, $temp_dir_real ) : strpos( $dir, $temp_dir_real ) ) | ||
| || 0 === ( $is_windows ? stripos( $dir, "/private{$temp_dir_original}" ) : strpos( $dir, "/private{$temp_dir_original}" ) ) | ||
| || 0 === ( $is_windows ? stripos( $dir, "/private{$temp_dir_real}" ) : strpos( $dir, "/private{$temp_dir_real}" ) ); |
There was a problem hiding this comment.
The logic for checking if the directory is within the temporary directory is quite repetitive and difficult to read. Since you are checking multiple candidates against the same directory using a conditional comparison function (stripos vs strpos), you can simplify this by using a loop. This improves maintainability and reduces the risk of errors when adding new candidates.
$compare = $is_windows ? 'stripos' : 'strpos';
$in_temp = false;
foreach ( [ $temp_dir_original, $temp_dir_real ] as $temp_path ) {
if ( 0 === $compare( $dir, $temp_path ) || 0 === $compare( $dir, "/private{$temp_path}" ) ) {
$in_temp = true;
break;
}
}
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
No description provided.