Skip to content

Commit 35ff82d

Browse files
committed
[Refactor] Always expect id field when creating paginator
1 parent c8b46c3 commit 35ff82d

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file. This projec
88
### Changed
99

1010
- Upgrade to Laravel 10 and set minimum PHP version to 8.1.
11+
- **BREAKING**: The schema's id field must now always be provided to the `CursorPagination::make()` method and/or
12+
constructor.
1113

1214
## [2.1.0] - 2023-01-24
1315

Diff for: src/CursorPagination.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ class CursorPagination implements Paginator
3131
{
3232
use HasPageMeta;
3333

34-
/**
35-
* @var ID|null
36-
*/
37-
private ?ID $id;
38-
3934
/**
4035
* @var string
4136
*/
@@ -79,22 +74,21 @@ class CursorPagination implements Paginator
7974
/**
8075
* Fluent constructor.
8176
*
82-
* @param ID|null $id
77+
* @param ID $id
8378
* @return CursorPagination
8479
*/
85-
public static function make(ID $id = null): self
80+
public static function make(ID $id): self
8681
{
8782
return new static($id);
8883
}
8984

9085
/**
9186
* CursorPagination constructor.
9287
*
93-
* @param ID|null $id
88+
* @param ID $id
9489
*/
95-
public function __construct(ID $id = null)
90+
public function __construct(private readonly ID $id)
9691
{
97-
$this->id = $id;
9892
$this->before = 'before';
9993
$this->after = 'after';
10094
$this->limit = 'limit';

Diff for: tests/lib/Acceptance/Test.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use LaravelJsonApi\CursorPagination\CursorPage;
3131
use LaravelJsonApi\CursorPagination\CursorPagination;
3232
use LaravelJsonApi\CursorPagination\Tests\EncodedId;
33+
use LaravelJsonApi\Eloquent\Fields\ID;
3334

3435
class Test extends TestCase
3536
{
@@ -61,7 +62,9 @@ protected function setUp(): void
6162
{
6263
parent::setUp();
6364

64-
$this->paginator = CursorPagination::make();
65+
$this->paginator = CursorPagination::make(
66+
ID::make()->uuid()
67+
);
6568

6669
$this->videos = $this
6770
->getMockBuilder(VideoSchema::class)

0 commit comments

Comments
 (0)