From 3e363e978f54cd7b46559f98f7417b2b018ecc2b Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Thu, 9 May 2024 20:32:47 +0700 Subject: [PATCH 1/2] feat: throw exception if a boundary value is null --- CHANGELOG.md | 1 + .../Exception/NullBoundaryValueException.php | 18 ++++++++++++++++++ .../src/Internal/SelectableKeysetItem.php | 5 +++++ .../src/Internal/QueryBuilderKeysetItem.php | 7 +++++++ 4 files changed, 31 insertions(+) create mode 100644 packages/rekapager-contracts/src/Exception/NullBoundaryValueException.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b61bfa..3679622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * refactor: remove configuration from API Platform bundle, will try to reuse standard API Platform extra properties. +* feat: throw exception if a boundary value is null # 0.8.1 diff --git a/packages/rekapager-contracts/src/Exception/NullBoundaryValueException.php b/packages/rekapager-contracts/src/Exception/NullBoundaryValueException.php new file mode 100644 index 0000000..abf69b1 --- /dev/null +++ b/packages/rekapager-contracts/src/Exception/NullBoundaryValueException.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +namespace Rekalogika\Contracts\Rekapager\Exception; + +class NullBoundaryValueException extends UnexpectedValueException +{ +} diff --git a/packages/rekapager-doctrine-collections-adapter/src/Internal/SelectableKeysetItem.php b/packages/rekapager-doctrine-collections-adapter/src/Internal/SelectableKeysetItem.php index 1aa29f0..04b2fae 100644 --- a/packages/rekapager-doctrine-collections-adapter/src/Internal/SelectableKeysetItem.php +++ b/packages/rekapager-doctrine-collections-adapter/src/Internal/SelectableKeysetItem.php @@ -14,6 +14,7 @@ namespace Rekalogika\Rekapager\Doctrine\Collections\Internal; use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor; +use Rekalogika\Contracts\Rekapager\Exception\NullBoundaryValueException; use Rekalogika\Rekapager\Keyset\Contracts\KeysetItemInterface; /** @@ -66,6 +67,10 @@ public function getValuesForBoundary(): array /** @var mixed $value */ $value = ClosureExpressionVisitor::getObjectFieldValue($this->objectOrArrayValue, $property); + if ($value === null) { + throw new NullBoundaryValueException(sprintf('The property "%s" of the value "%s" is a boundary value of this pagination, but it is found to be null. Null value in a boundary value is not supported.', $property, get_debug_type($value))); + } + /** @psalm-suppress MixedAssignment */ $result[$property] = $value; } diff --git a/packages/rekapager-doctrine-orm-adapter/src/Internal/QueryBuilderKeysetItem.php b/packages/rekapager-doctrine-orm-adapter/src/Internal/QueryBuilderKeysetItem.php index 91a57bc..030fea5 100644 --- a/packages/rekapager-doctrine-orm-adapter/src/Internal/QueryBuilderKeysetItem.php +++ b/packages/rekapager-doctrine-orm-adapter/src/Internal/QueryBuilderKeysetItem.php @@ -13,6 +13,7 @@ namespace Rekalogika\Rekapager\Doctrine\ORM\Internal; +use Rekalogika\Contracts\Rekapager\Exception\NullBoundaryValueException; use Rekalogika\Rekapager\Keyset\Contracts\KeysetItemInterface; /** @@ -34,6 +35,12 @@ public function __construct( private readonly mixed $value, private readonly array $boundaryValues, ) { + /** @var mixed $v */ + foreach ($boundaryValues as $k => $v) { + if ($v === null) { + throw new NullBoundaryValueException(sprintf('The property "%s" of the value "%s" is a boundary value of this pagination, but it is found to be null. Null value in a boundary value is not supported.', $k, get_debug_type($value))); + } + } } public function getKey(): mixed From ade521b9aeeb4e86dadde52eb3298ef000118c33 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Thu, 9 May 2024 20:45:22 +0700 Subject: [PATCH 2/2] satisfy psalm --- packages/rekapager-bundle/src/Twig/RekapagerExtension.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/rekapager-bundle/src/Twig/RekapagerExtension.php b/packages/rekapager-bundle/src/Twig/RekapagerExtension.php index 1365de5..79ff116 100644 --- a/packages/rekapager-bundle/src/Twig/RekapagerExtension.php +++ b/packages/rekapager-bundle/src/Twig/RekapagerExtension.php @@ -20,6 +20,7 @@ class RekapagerExtension extends AbstractExtension { public function getFunctions(): array { + /** @psalm-suppress InvalidArgument */ return [ new TwigFunction( 'rekapager', @@ -38,7 +39,7 @@ public function getFunctions(): array ]; } - private function renderInfiniteScrolling(): string + public function renderInfiniteScrolling(): string { return 'data-controller="rekalogika--rekapager-bundle--infinite-scrolling"'; }