Wrap data with Task before passing to TasksResults#864
Wrap data with Task before passing to TasksResults#864norkunas merged 1 commit intomeilisearch:mainfrom
Task before passing to TasksResults#864Conversation
📝 WalkthroughWalkthroughTasksResults is now final; its constructor requires mapped Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant IndexesEndpoint as Indexes Endpoint
participant HTTP as HTTP Client
participant TaskFactory as Task::fromArray
participant TasksResults as TasksResults
Client->>IndexesEndpoint: getTasks(options)
IndexesEndpoint->>HTTP: GET /tasks with query/options
HTTP-->>IndexesEndpoint: response { results: [array...], from, limit, next, total }
IndexesEndpoint->>TaskFactory: Task::fromArray(arrayItem, partial(waitTask, http))
TaskFactory-->>IndexesEndpoint: Task instance
IndexesEndpoint->>TasksResults: new TasksResults({ results: [Task,...], from, limit, next, total })
TasksResults-->>Client: TasksResults (results contain Task objects)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/Contracts/TasksResults.php`:
- Around line 29-45: The TasksResults constructor is assigning $params['next']
which can be null, but the docblock and property expect a non-negative-int;
update the signature and property to accept null by changing the array docblock
for 'next' to allow null (non-negative-int|null) and adjust the TasksResults
class property declaration (e.g. $next) to a nullable type, and ensure the
__construct continues to assign $this->next = $params['next'] without forcing a
non-null cast so null values are preserved.
0fc1994 to
662a966
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Contracts/TasksResults.php (1)
19-22: Fix nullable handling for$from- pipeline failure.The pipeline failure indicates that
$params['from']can benullwhen the API returns no results, but the property is typed asint. This is the same pattern as the$nextfield which was already made nullable."If from is set with an out of bounds task uid, the response returns the tasks that are the nearest to the specified uid." However, the Meilisearch API specification indicates thatfromcan benullwhen no tasks exist or when paginating past all results.🐛 Proposed fix to make `$from` nullable
/** - * `@var` non-negative-int + * `@var` non-negative-int|null */ -private int $from; +private ?int $from; /** * `@param` array{ * results: array<int, Task>, - * from: non-negative-int, + * from: non-negative-int|null, * limit: non-negative-int, * next: non-negative-int|null, * total: non-negative-int * } $params */ public function __construct(array $params) { parent::__construct($params['results']); $this->from = $params['from']; $this->limit = $params['limit']; $this->next = $params['next']; $this->total = $params['total']; }Also update
getFrom()return type:/** - * `@return` non-negative-int + * `@return` non-negative-int|null */ -public function getFrom(): int +public function getFrom(): ?int { return $this->from; }And update
toArray()docblock:/** * `@return` array{ * results: array<int, Task>, - * from: non-negative-int, + * from: non-negative-int|null, * limit: non-negative-int, * next: non-negative-int|null, * total: non-negative-int * } */Also applies to: 29-45
662a966 to
4a34718
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #864 +/- ##
==========================================
- Coverage 89.78% 87.25% -2.53%
==========================================
Files 59 81 +22
Lines 1449 1766 +317
==========================================
+ Hits 1301 1541 +240
- Misses 148 225 +77 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/Contracts/TasksResults.php`:
- Around line 88-96: The docblock for TasksResults::toArray() incorrectly allows
next to be null; update the return annotation so next is non-negative-int
(remove the |null) to match the non-nullable property $next and the coercion
logic in the constructor and toArray() method (refer to class TasksResults,
property $next, and method toArray()).
6f2c6ca to
208a981
Compare
208a981 to
ba7669c
Compare
Pull Request
Related issue
Part of #842
What does this PR do?
Taskbefore passing toTasksResultsMigration guide
TasksResultsConstructorTasks::all()Return ValuePR checklist
Please check if your PR fulfills the following requirements:
Summary by CodeRabbit
Breaking Changes
Improvements