From 35d151b70df1daa3e9a0d46377c5fcbf0a2d4f57 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 10 Aug 2023 14:46:04 +0200 Subject: [PATCH] Sort Trait: Make `$sort` nullable and adjust code accordingly - Update phpDoc --- library/Businessprocess/Common/Sort.php | 12 ++++++++---- library/Businessprocess/Renderer/Renderer.php | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/library/Businessprocess/Common/Sort.php b/library/Businessprocess/Common/Sort.php index 3b0f6d4..4728af3 100644 --- a/library/Businessprocess/Common/Sort.php +++ b/library/Businessprocess/Common/Sort.php @@ -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) { diff --git a/library/Businessprocess/Renderer/Renderer.php b/library/Businessprocess/Renderer/Renderer.php index 9917ed6..6aa1363 100644 --- a/library/Businessprocess/Renderer/Renderer.php +++ b/library/Businessprocess/Renderer/Renderer.php @@ -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);