[Finder] fix reverse sorting custom-ordering functions

This commit is contained in:
Nicolas Grekas 2018-10-10 06:30:17 -07:00
parent 0ea1adf3cc
commit 4d70a0b7d4

View File

@ -73,7 +73,7 @@ class SortableIterator implements \IteratorAggregate
} elseif (self::SORT_BY_NONE === $sort) {
$this->sort = $order;
} elseif (\is_callable($sort)) {
$this->sort = $sort;
$this->sort = $reverseOrder ? function ($a, $b) use ($sort) { return -\call_user_func($sort, $a, $b); } : $sort;
} else {
throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
}