diff --git a/src/Exception/InvalidPaginationArgumentException.php b/src/Exception/InvalidPaginationArgumentException.php index 95f05f6..631e60e 100644 --- a/src/Exception/InvalidPaginationArgumentException.php +++ b/src/Exception/InvalidPaginationArgumentException.php @@ -26,9 +26,9 @@ class InvalidPaginationArgumentException extends \InvalidArgumentException imple /** * @param array $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, @@ -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 */ @@ -69,8 +69,8 @@ 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 @@ -78,8 +78,8 @@ public static function forInvalidParameter( public static function forInvalidZeroLimit(int $offset, int $limit, int $nowCount): self { $parameters = [ - 'offset' => $offset, - 'limit' => $limit, + 'offset' => $offset, + 'limit' => $limit, 'nowCount' => $nowCount, ]; diff --git a/src/Exception/InvalidPaginationResultException.php b/src/Exception/InvalidPaginationResultException.php index a811d4d..369573f 100644 --- a/src/Exception/InvalidPaginationResultException.php +++ b/src/Exception/InvalidPaginationResultException.php @@ -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 */ @@ -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 diff --git a/src/OffsetAdapter.php b/src/OffsetAdapter.php index 235e245..91041cf 100644 --- a/src/OffsetAdapter.php +++ b/src/OffsetAdapter.php @@ -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 - * * @throws \Throwable + * + * @return OffsetResult */ 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 $result */ + /** @var OffsetResult $result */ $result = OffsetResult::empty(); return $result; @@ -85,9 +85,9 @@ public function execute(int $offset, int $limit, int $nowCount = 0): OffsetResul * @param int $limit * @param int $nowCount * - * @return \Generator - * * @throws \Throwable + * + * @return \Generator */ public function generator(int $offset, int $limit, int $nowCount = 0): \Generator { @@ -103,9 +103,9 @@ public function generator(int $offset, int $limit, int $nowCount = 0): \Generato * @param int $limit * @param int $nowCount * - * @return array - * * @throws \Throwable + * + * @return array */ public function fetchAll(int $offset, int $limit, int $nowCount = 0): array { @@ -113,9 +113,9 @@ public function fetchAll(int $offset, int $limit, int $nowCount = 0): array } /** - * @return \Generator<\Generator> - * * @throws \Throwable + * + * @return \Generator<\Generator> */ protected function logic(int $offset, int $limit, int $nowCount): \Generator { @@ -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', }; diff --git a/src/OffsetResult.php b/src/OffsetResult.php index 3c39cef..93a6037 100644 --- a/src/OffsetResult.php +++ b/src/OffsetResult.php @@ -46,6 +46,7 @@ public static function empty(): self { /** @return \Generator<\Generator> */ $emptyGenerator = static fn () => yield from []; + return new self($emptyGenerator()); } @@ -65,9 +66,9 @@ public function fetch(): mixed } /** - * @return array - * * @throws InvalidPaginationResultException + * + * @return array */ public function fetchAll(): array { diff --git a/src/SourceCallbackAdapter.php b/src/SourceCallbackAdapter.php index 251a1b2..0f494ca 100644 --- a/src/SourceCallbackAdapter.php +++ b/src/SourceCallbackAdapter.php @@ -37,9 +37,9 @@ public function __construct(private $callback) } /** - * @return \Generator - * * @throws InvalidPaginationResultException + * + * @return \Generator */ public function execute(int $page, int $pageSize): \Generator { diff --git a/src/SourceInterface.php b/src/SourceInterface.php index 89ccc6d..835e8e8 100644 --- a/src/SourceInterface.php +++ b/src/SourceInterface.php @@ -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 Generator yielding items for the requested page - * * @throws \Throwable Any implementation-specific errors should be thrown directly + * + * @return \Generator Generator yielding items for the requested page */ public function execute(int $page, int $pageSize): \Generator; } diff --git a/tests/PropertyBasedTest.php b/tests/PropertyBasedTest.php index 08b3204..f4e6392 100644 --- a/tests/PropertyBasedTest.php +++ b/tests/PropertyBasedTest.php @@ -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)], ]); } diff --git a/tests/SourceCallbackAdapterTest.php b/tests/SourceCallbackAdapterTest.php index 5feac79..c28a876 100644 --- a/tests/SourceCallbackAdapterTest.php +++ b/tests/SourceCallbackAdapterTest.php @@ -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'], ]; } @@ -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], ]; }