Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: throw exception if a boundary value is null #47

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion packages/rekapager-bundle/src/Twig/RekapagerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RekapagerExtension extends AbstractExtension
{
public function getFunctions(): array
{
/** @psalm-suppress InvalidArgument */
return [
new TwigFunction(
'rekapager',
Expand All @@ -38,7 +39,7 @@ public function getFunctions(): array
];
}

private function renderInfiniteScrolling(): string
public function renderInfiniteScrolling(): string
{
return 'data-controller="rekalogika--rekapager-bundle--infinite-scrolling"';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/rekapager package.
*
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev>
*
* 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
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Rekalogika\Rekapager\Doctrine\ORM\Internal;

use Rekalogika\Contracts\Rekapager\Exception\NullBoundaryValueException;
use Rekalogika\Rekapager\Keyset\Contracts\KeysetItemInterface;

/**
Expand All @@ -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
Expand Down
Loading