Sort Trait: Make $sort nullable and adjust code accordingly

- Update phpDoc
This commit is contained in:
Sukhwinder Dhillon 2023-08-10 14:46:04 +02:00
parent 92e982bf3d
commit 35d151b70d
2 changed files with 12 additions and 4 deletions

View file

@ -10,10 +10,10 @@ use ipl\Stdlib\Str;
trait Sort
{
/** @var string Current sort specification */
/** @var ?string Current sort specification */
protected $sort;
/** @var callable Actual sorting function */
/** @var ?callable Actual sorting function */
protected $sortFn;
/**
@ -29,14 +29,18 @@ trait Sort
/**
* Set the sort specification
*
* @param string $sort
* @param ?string $sort
*
* @return $this
*
* @throws InvalidArgumentException When sorting according to the specified specification is not possible
*/
public function setSort(string $sort): self
public function setSort(?string $sort): self
{
if (empty($sort)) {
return $this;
}
list($sortBy, $direction) = Str::symmetricSplit($sort, ' ', 2, 'asc');
switch ($sortBy) {

View file

@ -145,6 +145,10 @@ abstract class Renderer extends HtmlDocument
*/
public function appliesCustomSorting(): bool
{
if (empty($this->getSort())) {
return false;
}
list($sortBy, $_) = Str::symmetricSplit($this->getSort(), ' ', 2);
list($defaultSortBy, $_) = Str::symmetricSplit($this->getDefaultSort(), ' ', 2);