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-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"'; } 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