diff --git a/src/UI/DataGrid/Column.php b/src/UI/DataGrid/Column.php index 893fb4a..29120f4 100644 --- a/src/UI/DataGrid/Column.php +++ b/src/UI/DataGrid/Column.php @@ -12,10 +12,9 @@ public function __construct(public string $name, public string $label, private D } /** - * @phpstan-param DataGrid::Order*|null $defaultOrder * @return $this */ - public function enableSort(string|null $defaultOrder = null): self + public function enableSort(ColumnOrder|null $defaultOrder = null): self { $this->sort = true; if ($defaultOrder !== null) { @@ -31,27 +30,27 @@ public function canSort(): bool return $this->sort; } - public function getNewState(): string + public function getNewState(): ColumnOrder { if ($this->isAsc()) { - return DataGrid::OrderDesc; + return ColumnOrder::Desc; } if ($this->isDesc()) { - return ''; + return ColumnOrder::Undefined; } - return DataGrid::OrderAsc; + return ColumnOrder::Asc; } public function isAsc(): bool { - return $this->grid->orderColumn === $this->name && $this->grid->orderType === DataGrid::OrderAsc; + return $this->grid->orderColumn === $this->name && $this->grid->orderType === ColumnOrder::Asc; } public function isDesc(): bool { - return $this->grid->orderColumn === $this->name && $this->grid->orderType === DataGrid::OrderDesc; + return $this->grid->orderColumn === $this->name && $this->grid->orderType === ColumnOrder::Desc; } } diff --git a/src/UI/DataGrid/ColumnOrder.php b/src/UI/DataGrid/ColumnOrder.php new file mode 100644 index 0000000..e522c39 --- /dev/null +++ b/src/UI/DataGrid/ColumnOrder.php @@ -0,0 +1,14 @@ + */ @@ -39,9 +36,8 @@ final class DataGrid extends BaseControl #[Persistent] public string|null $orderColumn = null; - /** @var self::Order* */ #[Persistent] - public string $orderType = self::OrderAsc; + public ColumnOrder $orderType = ColumnOrder::Undefined; /** @var int<1, max> */ #[Persistent] diff --git a/src/UI/DataGrid/OrderParameter.php b/src/UI/DataGrid/OrderParameter.php index dfbfa43..ebc73bd 100644 --- a/src/UI/DataGrid/OrderParameter.php +++ b/src/UI/DataGrid/OrderParameter.php @@ -5,15 +5,11 @@ final class OrderParameter { - /** @phpstan-var DataGrid::Order* */ - private string $direction; - - /** - * @phpstan-param DataGrid::Order* $direction - */ - public function __construct(private readonly string $column, string $direction) + public function __construct( + private readonly string $column, + private readonly ColumnOrder $order, + ) { - $this->direction = $direction; } public function getColumn(): string @@ -21,22 +17,19 @@ public function getColumn(): string return $this->column; } - /** - * @phpstan-return DataGrid::Order* - */ - public function getDirection(): string + public function getOrder(): ColumnOrder { - return $this->direction; + return $this->order; } public function isAsc(): bool { - return $this->direction === DataGrid::OrderAsc; + return $this->order === ColumnOrder::Asc; } public function isDesc(): bool { - return $this->direction === DataGrid::OrderDesc; + return $this->order === ColumnOrder::Desc; } }