Skip to content

Commit 284800b

Browse files
committed
fix: current comment of FILETREE_SORT
1 parent 52eafca commit 284800b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ $fileList = $torrent->getFileList();
217217
* - TorrentFile::FILETREE_SORT_NORMAL : not sort, also means sort by torrent file parsed order
218218
* - TorrentFile::FILETREE_SORT_STRING : sort by filename ASC ("natural ordering" and "case-insensitively")
219219
* - TorrentFile::FILETREE_SORT_FOLDER : sort by filetype (first folder, then file)
220-
* - TorrentFile::FILETREE_SORT_NATURAL: sort by both filetype and filename ( same as `TorrentFile::FILETREE_SORT_NAME | TorrentFile::FILETREE_SORT_FOLDER` )
220+
* - TorrentFile::FILETREE_SORT_NATURAL: sort by both filetype and filename ( same as `TorrentFile::FILETREE_SORT_STRING | TorrentFile::FILETREE_SORT_FOLDER` )
221221
*
222222
*/
223-
$fileTree = $torrent->getFileTree(?$sortType = self::FILETREE_SORT_NORMAL);
223+
$fileTree = $torrent->getFileTree(?$sortType = TorrentFile::FILETREE_SORT_NORMAL);
224224

225225
// 6. Other method
226226
$torrent->cleanCache();

src/TorrentFile.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TorrentFile
4040
public const FILETREE_SORT_NORMAL = 0x00;
4141
public const FILETREE_SORT_STRING = 0x01;
4242
public const FILETREE_SORT_FOLDER = 0x10;
43-
public const FILETREE_SORT_NATURAL = 0x11; // same as self::FILETREE_SORT_NAME | self::FILETREE_SORT_FOLDER
43+
public const FILETREE_SORT_NATURAL = 0x11; // same as `self::FILETREE_SORT_STRING | self::FILETREE_SORT_FOLDER`
4444

4545
// store torrent dict
4646
private $data;
@@ -700,16 +700,16 @@ public function getFileList()
700700
return $this->parse()['files'];
701701
}
702702

703-
private static function sortFileTreeRecursive(array &$fileTree, $sortByName = false, $sortByFolder = false): array
703+
private static function sortFileTreeRecursive(array &$fileTree, $sortByString = false, $sortByFolder = false): array
704704
{
705-
if ($sortByName) {
705+
if ($sortByString) {
706706
ksort($fileTree, SORT_NATURAL | SORT_FLAG_CASE);
707707
}
708708

709709
$isoFile = [];
710710
foreach ($fileTree as $key => &$item) {
711711
if (is_array($item)) {
712-
$fileTree[$key] = self::sortFileTreeRecursive($item, $sortByName, $sortByFolder);
712+
$fileTree[$key] = self::sortFileTreeRecursive($item, $sortByString, $sortByFolder);
713713
} else if ($sortByFolder) {
714714
$isoFile[$key] = $item;
715715
unset($fileTree[$key]);
@@ -734,11 +734,11 @@ public function getFileTree($sortType = self::FILETREE_SORT_NORMAL)
734734
{
735735
$fileTree = $this->parse()['fileTree'];
736736

737-
$sortByName = ($sortType & self::FILETREE_SORT_STRING) === self::FILETREE_SORT_STRING;
737+
$sortByString = ($sortType & self::FILETREE_SORT_STRING) === self::FILETREE_SORT_STRING;
738738
$sortByFolder = ($sortType & self::FILETREE_SORT_FOLDER) === self::FILETREE_SORT_FOLDER;
739739

740-
if ($sortByName || $sortByFolder) {
741-
self::sortFileTreeRecursive($fileTree, $sortByName, $sortByFolder);
740+
if ($sortByString || $sortByFolder) {
741+
self::sortFileTreeRecursive($fileTree, $sortByString, $sortByFolder);
742742
}
743743

744744
return $fileTree;

0 commit comments

Comments
 (0)