diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannelControls.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannelControls.php index 4b4be6b5a..a6cbcea68 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannelControls.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannelControls.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find channel controls entities query @@ -72,17 +70,13 @@ public function byChannelId(Uuid\UuidInterface $channelId): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannelProperties.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannelProperties.php index 072bb928f..233ebb99d 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannelProperties.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannelProperties.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find channel properties entities query @@ -116,17 +114,13 @@ public function queryable(bool $state): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannels.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannels.php index d42d8a4d7..3861fe174 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannels.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindChannels.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find device channels entities query @@ -113,17 +111,13 @@ public function withSettableProperties(): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectorControls.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectorControls.php index 075101548..8a51c1b3f 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectorControls.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectorControls.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find connector properties entities query @@ -72,17 +70,13 @@ public function byConnectorId(Uuid\UuidInterface $connectorId): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectorProperties.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectorProperties.php index 508170175..cbff0b7ab 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectorProperties.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectorProperties.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find connector properties entities query @@ -101,17 +99,13 @@ public function queryable(bool $state): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectors.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectors.php index ebfedeb1f..e137be56d 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectors.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindConnectors.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find connectors entities query @@ -57,17 +55,13 @@ public function byIdentifier(string $identifier): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindDeviceControls.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindDeviceControls.php index d564dcf64..d9bc12402 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindDeviceControls.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindDeviceControls.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find device controls entities query @@ -72,17 +70,13 @@ public function byDeviceId(Uuid\UuidInterface $deviceId): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindDeviceProperties.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindDeviceProperties.php index 37bd6cf47..e16b5f040 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindDeviceProperties.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindDeviceProperties.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find device properties entities query @@ -116,17 +114,13 @@ public function queryable(bool $state): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Devices/src/Queries/Entities/FindDevices.php b/src/FastyBird/Module/Devices/src/Queries/Entities/FindDevices.php index 9ca7c7aad..be3ddcb03 100644 --- a/src/FastyBird/Module/Devices/src/Queries/Entities/FindDevices.php +++ b/src/FastyBird/Module/Devices/src/Queries/Entities/FindDevices.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Devices\Entities; -use FastyBird\Module\Devices\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find devices entities query @@ -144,17 +142,13 @@ public function withChannels(): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; } diff --git a/src/FastyBird/Module/Triggers/src/Queries/Entities/FindTriggerControls.php b/src/FastyBird/Module/Triggers/src/Queries/Entities/FindTriggerControls.php index ffcafe404..2e8382146 100644 --- a/src/FastyBird/Module/Triggers/src/Queries/Entities/FindTriggerControls.php +++ b/src/FastyBird/Module/Triggers/src/Queries/Entities/FindTriggerControls.php @@ -19,10 +19,8 @@ use Doctrine\Common; use Doctrine\ORM; use FastyBird\Module\Triggers\Entities; -use FastyBird\Module\Triggers\Exceptions; use IPub\DoctrineOrmQuery; use Ramsey\Uuid; -use function in_array; /** * Find trigger properties entities query @@ -71,17 +69,13 @@ public function forTrigger(Entities\Triggers\Trigger $trigger): void }; } - /** - * @throws Exceptions\InvalidArgument - */ - public function sortBy(string $sortBy, string $sortDir = Common\Collections\Criteria::ASC): void + public function sortBy( + string $sortBy, + Common\Collections\Order $sortDir = Common\Collections\Order::Ascending, + ): void { - if (!in_array($sortDir, [Common\Collections\Criteria::ASC, Common\Collections\Criteria::DESC], true)) { - throw new Exceptions\InvalidArgument('Provided sortDir value is not valid.'); - } - $this->filter[] = static function (ORM\QueryBuilder $qb) use ($sortBy, $sortDir): void { - $qb->addOrderBy($sortBy, $sortDir); + $qb->addOrderBy($sortBy, $sortDir->value); }; }