This question has been on my mind for some time. I'm currently writing a repository with the usual methods: save, getById, getList, delete and deleteById. What is the correct return for each method?

- should the method return **$this**, **$dto** or (true || false)?
Repository::getById(int $id)
- for this one I'm pretty sure that it should return the corresponding DTO
Repository::getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) 
- should the method (always) return \Magento\Framework\Api\SearchResults $searchResult
- should the method return **$this** or (true or false)? 
Repository::deleteById(int $id) 
- should the method return **$this** or (true or false)?
  • Can you please mention here repository class? Commented Jun 30, 2019 at 9:27
  • I do not have a specific Repository or DTO class in mind. With this question I'm just looking for general advice (or best practices) when implementing a CRUD functionality for a new custom entity.
    – Radu
    Commented Jun 30, 2019 at 9:37
  • Why not void for delete, and save? If something wrong happen, an exception is raised (couldnotdeleteexceptio and couodnotsavecexception)
    – Mr.K
    Commented Jun 30, 2019 at 15:42

1 Answer 1


Personally I think the first three you've got correct.

Although clarifying save. This should be false on failure.

For me delete & deletebyid should return a true / false depending on result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.