Skip to content

Commit

Permalink
Make Api\SearchResults implement Api\SearchResultsInterface
Browse files Browse the repository at this point in the history
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` or
one 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 implement `Api\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 anyway.
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.
  • Loading branch information
Vinai committed Jun 27, 2015
1 parent b67a5e0 commit cbc85da
Show file tree
Hide file tree
Showing 37 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public function getItems();
* @param \Magento\Catalog\Api\Data\CategoryAttributeInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public function getItems();
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public function getItems();
* @param \Magento\Catalog\Api\Data\ProductInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public function getItems();
* @param \Magento\CatalogInventory\Api\Data\StockInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getItems();
* @param \Magento\CatalogInventory\Api\Data\StockItemInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);

/**
* Get search criteria.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getItems();
* @param \Magento\CatalogInventory\Api\Data\StockStatusInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);

/**
* Get search criteria.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Cms\Api\Data\BlockInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Cms\Api\Data\PageInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Customer\Api\Data\AddressInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Customer\Api\Data\CustomerInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Customer\Api\Data\GroupInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public function getItems();
* @param \Magento\Eav\Api\Data\AttributeGroupInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public function getItems();
* @param \Magento\Eav\Api\Data\AttributeInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public function getItems();
* @param \Magento\Eav\Api\Data\AttributeSetInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getItems();
* @param \Magento\Quote\Api\Data\CartInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);

/**
* Get search criteria.
Expand All @@ -50,7 +50,7 @@ public function getSearchCriteria();
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return $this
*/
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null);
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);

/**
* Get total count.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\CreditmemoCommentInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\CreditmemoItemInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\CreditmemoInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\InvoiceCommentInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\InvoiceItemInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\InvoiceInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\OrderAddressInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\OrderItemInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\OrderPaymentInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\OrderStatusHistoryInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\ShipmentCommentInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\ShipmentItemInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\ShipmentInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\ShipmentTrackInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Sales\Api\Data\TransactionInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public function getItems();
* @param \Magento\Tax\Api\Data\TaxClassInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public function getItems();
* @param \Magento\Tax\Api\Data\TaxRateInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public function getItems();
* @param \Magento\Tax\Api\Data\TaxRuleInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public function testGetList()

$collection->expects($this->any())->method('getSize')->willReturn(2);
$collection->expects($this->any())->method('setItems')->with([$taxClassOne, $taxClassTwo]);
$collection->expects($this->any())->method('getItems')->willReturn([$taxClassOne, $taxClassTwo]);
$collection->expects($this->once())->method('setCurPage')->with(0);
$collection->expects($this->once())->method('setPageSize')->with(20);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public function getItems();
* @param \Magento\Ui\Api\Data\BookmarkInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);
}
6 changes: 3 additions & 3 deletions lib/internal/Magento/Framework/Api/SearchResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* SearchResults Service Data Object used for the search service requests
*/
class SearchResults extends AbstractSimpleObject
class SearchResults extends AbstractSimpleObject implements SearchResultsInterface
{
const KEY_ITEMS = 'items';
const KEY_SEARCH_CRITERIA = 'search_criteria';
Expand Down Expand Up @@ -49,10 +49,10 @@ public function getSearchCriteria()
/**
* Set search criteria
*
* @param \Magento\Framework\Api\SearchCriteria $searchCriteria
* @param SearchCriteriaInterface $searchCriteria
* @return $this
*/
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteria $searchCriteria)
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
return $this->setData(self::KEY_SEARCH_CRITERIA, $searchCriteria);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/Api/SearchResultsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getItems();
* @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
* @return $this
*/
public function setItems(array $items = null);
public function setItems(array $items);

/**
* Get search criteria.
Expand All @@ -41,7 +41,7 @@ public function getSearchCriteria();
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return $this
*/
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null);
public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);

/**
* Get total count.
Expand Down

0 comments on commit cbc85da

Please sign in to comment.