diff --git a/src/Exception/InvalidPaginationArgumentException.php b/src/Exception/InvalidPaginationArgumentException.php index 95f05f694e30715aedbab3e6a3e276ff5f496390..631e60eeebc07a84e926d7d3af41dea1bcc50be3 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 @@ class InvalidPaginationArgumentException extends \InvalidArgumentException imple * 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 @@ class InvalidPaginationArgumentException extends \InvalidArgumentException imple /** * 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 @@ class InvalidPaginationArgumentException extends \InvalidArgumentException imple 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 a811d4d9be717dc21e21cc5f0dff6dedb2087665..369573fa2698d21252810275fec6a39033bdeb2e 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 @@ class InvalidPaginationResultException extends \UnexpectedValueException impleme /** * 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 235e245883cbd9205a02e3bd5c6bc60449840b2d..91041cf3acb4c33f5e4578a4301a3b386786e17f 100644 --- a/src/OffsetAdapter.php +++ b/src/OffsetAdapter.php @@ -54,20 +54,20 @@ readonly class OffsetAdapter /** * 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 @@ readonly class OffsetAdapter * @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 @@ readonly class OffsetAdapter * @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 @@ readonly class OffsetAdapter } /** - * @return \Generator<\Generator> - * * @throws \Throwable + * + * @return \Generator<\Generator> */ protected function logic(int $offset, int $limit, int $nowCount): \Generator { @@ -155,8 +155,8 @@ readonly class OffsetAdapter 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 3c39cef093daf322274263428d7599446cb26c4d..93a60373b505e67d12f6dbcc9d7bb96c54ed4eea 100644 --- a/src/OffsetResult.php +++ b/src/OffsetResult.php @@ -46,6 +46,7 @@ class OffsetResult { /** @return \Generator<\Generator> */ $emptyGenerator = static fn () => yield from []; + return new self($emptyGenerator()); } @@ -65,9 +66,9 @@ class OffsetResult } /** - * @return array - * * @throws InvalidPaginationResultException + * + * @return array */ public function fetchAll(): array { diff --git a/src/SourceCallbackAdapter.php b/src/SourceCallbackAdapter.php index 251a1b2448d5bc224b67fbd3c2090668adc1b1dd..0f494cab577620386c198dbb4d72e52cfec81ab5 100644 --- a/src/SourceCallbackAdapter.php +++ b/src/SourceCallbackAdapter.php @@ -37,9 +37,9 @@ class SourceCallbackAdapter implements SourceInterface } /** - * @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 89ccc6d676abe1d4e02d475c7c3090b1ec556ab8..835e8e833b77ed9e0ff936d1f5c90c0689a95e24 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 08b3204b56f1614e85b5ea8a0fe9cb174593fdcb..f4e6392358e8d757b0b73dad02fce7f474f212b7 100644 --- a/tests/PropertyBasedTest.php +++ b/tests/PropertyBasedTest.php @@ -38,8 +38,8 @@ class PropertyBasedTest extends TestCase // 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 5feac79a6081093731f154e896baa0fe6d6395b3..c28a87631c5cffefa9b5f8ecd19d16145c8d8286 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 @@ class SourceCallbackAdapterTest extends TestCase { 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], ]; }