Changeset 53937
- Timestamp:
- 08/24/2022 01:49:36 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/abstract-testcase.php
r53832 r53937 1422 1422 */ 1423 1423 public function delete_folders( $path ) { 1424 $this->matched_dirs = array();1425 1424 if ( ! is_dir( $path ) ) { 1426 1425 return; 1427 1426 } 1428 1427 1429 $this->scandir( $path ); 1430 foreach ( array_reverse( $this->matched_dirs ) as $dir ) { 1428 $matched_dirs = $this->scandir( $path ); 1429 1430 foreach ( array_reverse( $matched_dirs ) as $dir ) { 1431 1431 rmdir( $dir ); 1432 1432 } 1433 1433 1434 rmdir( $path ); 1434 1435 } 1435 1436 1436 1437 /** 1437 * Retrieves all directories contained inside a directory and stores them in the `$matched_dirs` property.1438 * Retrieves all directories contained inside a directory. 1438 1439 * Hidden directories are ignored. 1439 1440 * … … 1441 1442 * 1442 1443 * @since 4.1.0 1444 * @since 6.1.0 No longer sets a (dynamic) property to keep track of the directories, 1445 * but returns an array of the directories instead. 1443 1446 * 1444 1447 * @param string $dir Path to the directory to scan. 1448 * @return string[] List of directories. 1445 1449 */ 1446 1450 public function scandir( $dir ) { 1451 $matched_dirs = array(); 1452 1447 1453 foreach ( scandir( $dir ) as $path ) { 1448 1454 if ( 0 !== strpos( $path, '.' ) && is_dir( $dir . '/' . $path ) ) { 1449 $this->matched_dirs[] = $dir . '/' . $path; 1450 $this->scandir( $dir . '/' . $path ); 1451 } 1452 } 1455 $matched_dirs[] = array( $dir . '/' . $path ); 1456 $matched_dirs[] = $this->scandir( $dir . '/' . $path ); 1457 } 1458 } 1459 1460 /* 1461 * Compatibility check for PHP < 7.4, where array_merge() expects at least one array. 1462 * See: https://3v4l.org/BIQMA 1463 */ 1464 if ( array() === $matched_dirs ) { 1465 return array(); 1466 } 1467 1468 return array_merge( ...$matched_dirs ); 1453 1469 } 1454 1470
Note: See TracChangeset
for help on using the changeset viewer.