Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Document returned array shape for sync methods #52070

Merged
merged 1 commit into from
Jul 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function toggle($ids, $touch = true)
* Sync the intermediate tables with a list of IDs without detaching.
*
* @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array $ids
* @return array
* @return array{attached: array, detached: array, updated: array}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the array inner types should really be defined (e.g., array<string, mixed> for instance)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I don't think we can be more specific than array<array-key, mixed>, which is the same as array.

*/
public function syncWithoutDetaching($ids)
{
Expand All @@ -79,7 +79,7 @@ public function syncWithoutDetaching($ids)
*
* @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array $ids
* @param bool $detaching
* @return array
* @return array{attached: array, detached: array, updated: array}
*/
public function sync($ids, $detaching = true)
{
Expand Down Expand Up @@ -133,7 +133,7 @@ public function sync($ids, $detaching = true)
* @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array $ids
* @param array $values
* @param bool $detaching
* @return array
* @return array{attached: array, detached: array, updated: array}
*/
public function syncWithPivotValues($ids, array $values, bool $detaching = true)
{
Expand Down
3 changes: 3 additions & 0 deletions types/Database/Eloquent/Relations.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ function test(User $user, Post $post, Comment $comment, ChildUser $child): void
assertType('Illuminate\Database\Eloquent\Collection<int, Illuminate\Types\Relations\Role>', $user->roles()->saveManyQuietly($roles));
assertType('array<int, Illuminate\Types\Relations\Role>', $user->roles()->saveManyQuietly($roles->all()));
assertType('array<int, Illuminate\Types\Relations\Role>', $user->roles()->createMany($roles));
assertType('array{attached: array, detached: array, updated: array}', $user->roles()->sync($roles));
assertType('array{attached: array, detached: array, updated: array}', $user->roles()->syncWithoutDetaching($roles));
assertType('array{attached: array, detached: array, updated: array}', $user->roles()->syncWithPivotValues($roles, []));
assertType('Illuminate\Support\LazyCollection<int, Illuminate\Types\Relations\Role>', $user->roles()->lazy());
assertType('Illuminate\Support\LazyCollection<int, Illuminate\Types\Relations\Role>', $user->roles()->lazyById());
assertType('Illuminate\Support\LazyCollection<int, Illuminate\Types\Relations\Role>', $user->roles()->cursor());
Expand Down