Skip to content
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
18 changes: 9 additions & 9 deletions src/Exception/InvalidPaginationArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class InvalidPaginationArgumentException extends \InvalidArgumentException imple

/**
* @param array<string, mixed> $parameters The parameter values that were provided
* @param string $message The error message
* @param int $code The error code (optional)
* @param \Throwable|null $previous The previous exception (optional)
* @param string $message The error message
* @param int $code The error code (optional)
* @param \Throwable|null $previous The previous exception (optional)
*/
public function __construct(
array $parameters,
Expand All @@ -44,8 +44,8 @@ public function __construct(
* Create an exception for invalid parameter values.
*
* @param string $parameterName The name of the invalid parameter
* @param mixed $value The invalid value
* @param string $description Description of what the parameter represents
* @param mixed $value The invalid value
* @param string $description Description of what the parameter represents
*
* @return self
*/
Expand All @@ -69,17 +69,17 @@ public static function forInvalidParameter(
/**
* Create an exception for invalid zero limit combinations.
*
* @param int $offset The offset value
* @param int $limit The limit value (should be 0)
* @param int $offset The offset value
* @param int $limit The limit value (should be 0)
* @param int $nowCount The nowCount value
*
* @return self
*/
public static function forInvalidZeroLimit(int $offset, int $limit, int $nowCount): self
{
$parameters = [
'offset' => $offset,
'limit' => $limit,
'offset' => $offset,
'limit' => $limit,
'nowCount' => $nowCount,
];

Expand Down
6 changes: 3 additions & 3 deletions src/Exception/InvalidPaginationResultException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class InvalidPaginationResultException extends \UnexpectedValueException impleme
/**
* Create an exception for invalid callback result type.
*
* @param mixed $result The invalid result from callback
* @param mixed $result The invalid result from callback
* @param string $expectedType The expected type
* @param string $context Additional context about where this occurred
* @param string $context Additional context about where this occurred
*
* @return self
*/
Expand All @@ -47,7 +47,7 @@ public static function forInvalidCallbackResult(mixed $result, string $expectedT
/**
* Create an exception for invalid source result type.
*
* @param mixed $result The invalid result
* @param mixed $result The invalid result
* @param string $expectedType The expected type/class
*
* @return self
Expand Down
26 changes: 13 additions & 13 deletions src/OffsetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ public static function fromCallback(callable $callback): self
/**
* Execute pagination request with offset and limit.
*
* @param int $offset Starting position (0-based)
* @param int $limit Maximum number of items to return
* @param int $offset Starting position (0-based)
* @param int $limit Maximum number of items to return
* @param int $nowCount Current count of items already fetched (used for progress tracking in multi-request scenarios)
*
* @return OffsetResult<T>
*
* @throws \Throwable
*
* @return OffsetResult<T>
*/
public function execute(int $offset, int $limit, int $nowCount = 0): OffsetResult
{
$this->assertArgumentsAreValid($offset, $limit, $nowCount);

if (0 === $offset && 0 === $limit && 0 === $nowCount) {
/** @var OffsetResult<never-return> $result */
/** @var OffsetResult<never-return> $result */
$result = OffsetResult::empty();

return $result;
Expand All @@ -85,9 +85,9 @@ public function execute(int $offset, int $limit, int $nowCount = 0): OffsetResul
* @param int $limit
* @param int $nowCount
*
* @return \Generator<T>
*
* @throws \Throwable
*
* @return \Generator<T>
*/
public function generator(int $offset, int $limit, int $nowCount = 0): \Generator
{
Expand All @@ -103,19 +103,19 @@ public function generator(int $offset, int $limit, int $nowCount = 0): \Generato
* @param int $limit
* @param int $nowCount
*
* @return array<T>
*
* @throws \Throwable
*
* @return array<T>
*/
public function fetchAll(int $offset, int $limit, int $nowCount = 0): array
{
return $this->execute($offset, $limit, $nowCount)->fetchAll();
}

/**
* @return \Generator<\Generator<T>>
*
* @throws \Throwable
*
* @return \Generator<\Generator<T>>
*/
protected function logic(int $offset, int $limit, int $nowCount): \Generator
{
Expand Down Expand Up @@ -155,8 +155,8 @@ private function assertArgumentsAreValid(int $offset, int $limit, int $nowCount)
foreach ([['offset', $offset], ['limit', $limit], ['nowCount', $nowCount]] as [$name, $value]) {
if (0 > $value) {
$description = match ($name) {
'offset' => 'starting position in the dataset',
'limit' => 'maximum number of items to return',
'offset' => 'starting position in the dataset',
'limit' => 'maximum number of items to return',
'nowCount' => 'number of items already fetched',
};

Expand Down
5 changes: 3 additions & 2 deletions src/OffsetResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static function empty(): self
{
/** @return \Generator<\Generator<never-return>> */
$emptyGenerator = static fn () => yield from [];

return new self($emptyGenerator());
}

Expand All @@ -65,9 +66,9 @@ public function fetch(): mixed
}

/**
* @return array<T>
*
* @throws InvalidPaginationResultException
*
* @return array<T>
*/
public function fetchAll(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/SourceCallbackAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function __construct(private $callback)
}

/**
* @return \Generator<T>
*
* @throws InvalidPaginationResultException
*
* @return \Generator<T>
*/
public function execute(int $page, int $pageSize): \Generator
{
Expand Down
6 changes: 3 additions & 3 deletions src/SourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ interface SourceInterface
* The generator will be consumed eagerly by the pagination system. If the generator
* yields fewer items than requested, it signals the end of available data.
*
* @param positive-int $page 1-based page number (≥1 for valid requests)
* @param positive-int $page 1-based page number (≥1 for valid requests)
* @param positive-int $pageSize Maximum number of items to return (≥0, 0 means no items)
*
* @return \Generator<T> Generator yielding items for the requested page
*
* @throws \Throwable Any implementation-specific errors should be thrown directly
*
* @return \Generator<T> Generator yielding items for the requested page
*/
public function execute(int $page, int $pageSize): \Generator;
}
4 changes: 2 additions & 2 deletions tests/PropertyBasedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static function randomDataSetsProvider(): array

// Add some specific edge cases
return array_merge($testCases, [
'empty' => [[]],
'single' => [['item']],
'empty' => [[]],
'single' => [['item']],
'multiple' => [range(1, 10)],
]);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/SourceCallbackAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class SourceCallbackAdapterTest extends TestCase
public static function invalidCallbackReturnProvider(): array
{
return [
'null' => [null, 'null'],
'array' => [['not', 'an', 'object'], 'array'],
'null' => [null, 'null'],
'array' => [['not', 'an', 'object'], 'array'],
'stdClass' => [new \stdClass(), 'stdClass'],
];
}
Expand All @@ -30,8 +30,8 @@ public static function parameterTestProvider(): array
{
return [
'various_parameters' => [5, 20, ['page5_size20'], false],
'zero_parameters' => [0, 0, ['zero_params'], true],
'large_parameters' => [1000, 5000, ['large_params'], true],
'zero_parameters' => [0, 0, ['zero_params'], true],
'large_parameters' => [1000, 5000, ['large_params'], true],
];
}

Expand Down
Loading