Skip to content

Commit a071f36

Browse files
committed
use iterator
1 parent f7c67eb commit a071f36

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/Context/FeatureContext.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,21 +1261,21 @@ public function move_files( $src, $dest ): void {
12611261
* @param string $dir
12621262
*/
12631263
public static function remove_dir( $dir ): void {
1264-
if ( ! file_exists( $dir ) ) {
1265-
return;
1266-
}
1267-
12681264
if ( ! is_dir( $dir ) ) {
1269-
unlink( $dir );
12701265
return;
12711266
}
12721267

1273-
foreach ( scandir( $dir ) as $item ) {
1274-
if ( '.' === $item || '..' === $item ) {
1275-
continue;
1276-
}
1268+
$iterator = new \RecursiveIteratorIterator(
1269+
new \RecursiveDirectoryIterator( $dir, \FilesystemIterator::SKIP_DOTS ),
1270+
\RecursiveIteratorIterator::CHILD_FIRST
1271+
);
12771272

1278-
self::remove_dir( $dir . '/' . $item );
1273+
foreach ( $iterator as $file ) {
1274+
if ( $file->isDir() ) {
1275+
rmdir( $file->getRealPath() );
1276+
} else {
1277+
unlink( $file->getRealPath() );
1278+
}
12791279
}
12801280

12811281
rmdir( $dir );

0 commit comments

Comments
 (0)