Rename Api\SearchCriteriaBuilder::addFilter() to addFilters() #1421
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 method name more descriptive and easier to understand.
Background
Having a method called
addFilter()
which take an array ofFilter
instances caused many doubletakes and facepalms during the m2 dev training.It seems as if the method name originated from the old collection
addFieldToFilter
from collections in Magento 1, where the condition type was set as a key in the passed argument array (e.g.addFieldToFilter('name', ['eq' => $filter])
).In fact, some integration tests even set such expectations on the searchCriteriaBuilder, for example app/code/Magento/Sales/Test/Unit/Model/Service/CreditmemoServiceTest.php.
However, this must be a bug because the array keys in the argument array are ignored, and the code only happened to work because the repositories in question default to using the 'eq' operator when applying the filter groups to the collection if no condition type is set on the filter instance.
Reasons for this PR
Make the method name more intuitive.
Naming definitely could still be improved, but at least it no longer is that misleading.
Maybe using
addFilterGroupWithFilters()
would be even more descriptive, but I chose the smaller change, since it probably is "good enough".Remove wrong examples of method usage from tests, so they don't serve as wrong documentation.