Make Api\SearchResults implement Api\SearchResultsInterface #1420
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Make the implementation actually fulfill the contract defined by the interface.
Background
The return type hints of almost all the repository implementations of the
getList()
method indicate a return type of
\Magento\Framework\Api\SearchResultsInterface
orone of its sub-interfaces.
One example of many is
\Magento\Catalog\Api\ProductRepositoryInterface::getList()
.The return type hint states it returns
\Magento\Catalog\Api\Data\ProductSearchResultsInterface
,which in turn extends
\Magento\Framework\Api\SearchResultsInterface
.However, the concrete implementation preference for that interface is
\Magento\Framework\Api\SearchResults
, which does not implement\Magento\Framework\Api\SearchResultsInterface
(or any interface for that matter).Reasons for this PR
This PR makes
Api\SearchResults
actually implementApi\SearchResultsInterface
,forcing all implementations to match the contract.
It also improves developer experience because this is pretty much what should be expected
of the code.
It also makes the preference configuration technically more correct, because the configured
concrete class is guaranteed to at least partially fulfill the contract defined by the
interface.