Pagerfanta icon indicating copy to clipboard operation
Pagerfanta copied to clipboard

Add an EmptyAdapter

Open stof opened this issue 1 year ago • 0 comments

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).

stof avatar Mar 12 '24 12:03 stof