Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Api\SearchCriteriaBuilder::addFilter() to addFilters() #1421

Merged
merged 1 commit into from
Jul 15, 2015
Merged

Rename Api\SearchCriteriaBuilder::addFilter() to addFilters() #1421

merged 1 commit into from
Jul 15, 2015

Conversation

Vinai
Copy link
Contributor

@Vinai Vinai commented Jun 28, 2015

Purpose

Make method name more descriptive and easier to understand.

Background

Having a method called addFilter() which take an array of Filter 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.

…ddFilters()

Purpose
==

Make method name more descriptive and easier to understand.

Background
==

Having a method called `addFilter()` which take an array of `Filter` 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.
@kokoc
Copy link
Member

kokoc commented Jul 7, 2015

@Vinai thank you for the contribution! Internal reference: MAGETWO-39815

@magento-team magento-team merged commit 4527e32 into magento:develop Jul 15, 2015
@Vinai Vinai deleted the add-filters-method branch July 16, 2015 08:52
@kokoc
Copy link
Member

kokoc commented Jul 16, 2015

@Vinai your code changes have just been deployed in version 1.0.0-beta. Thank you again for your contribution!

@Vinai
Copy link
Contributor Author

Vinai commented Jul 16, 2015

Thank you!

magento-team pushed a commit that referenced this pull request Aug 18, 2017
[EngCom] Public Pull Requests
 - MAGETWO-71659: Fix for url_rewrite on page delete via api #10568
 - MAGETWO-71617: Fixes Regression in 2.2 - menu.xml config ignored #10543
 - MAGETWO-71380: Fix JS translation search #10445
 - MAGETWO-71201: Improved calculating version hash for the js-translation.json file. #10378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants