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

Add an EmptyAdapter #55

Merged
merged 1 commit into from
Mar 24, 2024
Merged

Add an EmptyAdapter #55

merged 1 commit into from
Mar 24, 2024

Conversation

stof
Copy link
Contributor

@stof stof commented Mar 12, 2024

Unlike the NullAdapter, this adapter is always empty instead of allowing it to paginate an array of null values. Thanks to that, its generic type can fullfil types like AdapterInterface<Foo> with a non-nullable Foo type.

See https://phpstan.org/r/ada3d136-11fa-43f2-a5dc-dd282f008b3e for the difference it makes for phpstan and https://psalm.dev/r/cb09185906 for Psalm.

This EmptyAdapter is mostly meant to be used for conditional returns, where another branch of the execution would return a different adapter implementation (for instance to skip executing a DB query entirely when you know that the parameters you deal with cannot produce any results because they would execute a query with WHERE true = false).

Unlike the NullAdapter, this adapter is always empty instead of allowing
it to paginate an array of null values. Thanks to that, its generic type
can fullfil types like `AdapterInterface<Foo>` with a non-nullable `Foo`
type.
@mbabker mbabker merged commit a2f5f91 into BabDev:4.x Mar 24, 2024
52 checks passed
@mbabker mbabker added the enhancement New feature or request label Mar 24, 2024
@mbabker
Copy link
Member

mbabker commented Mar 24, 2024

Thanks! Released in 4.4.

@stof stof deleted the empty_adapter branch May 30, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants