Skip to content

Commit

Permalink
Merge pull request #280 from bancer/4.x-issue-279
Browse files Browse the repository at this point in the history
Rename children directories before parent in renameSubFolders
  • Loading branch information
markstory authored May 6, 2024
2 parents b17922a + 4997727 commit 1fd0a42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.0', '8.1']
php-version: ['8.0', '8.1', '8.2', '8.3']
prefer-lowest: ['']
include:
- php-version: '8.0'
Expand Down
18 changes: 16 additions & 2 deletions src/Command/FileRenameCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,24 @@ protected function renameSubFolders(string $path): void
RecursiveRegexIterator::SPLIT
);

// Collect directories in an array for sorting
$directories = [];
foreach ($templateDirs as $val) {
$directories[] = [
'source' => $val[0] . '/' . $folder,
'target' => $val[0] . '/' . strtolower($folder),
];
}

// Sort directories based on path length (longest to shortest) so that children before parents
usort($directories, function ($a, $b) {
return strlen($b['source']) - strlen($a['source']);
});

foreach ($directories as $directory) {
$this->renameWithCasing(
$val[0] . '/' . $folder,
$val[0] . '/' . strtolower($folder)
$directory['source'],
$directory['target']
);
}
}
Expand Down

0 comments on commit 1fd0a42

Please sign in to comment.