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

Removes requirement of the arguments in the constructor method (Filtered) in favor #615 #616

Merged
merged 8 commits into from
Jun 14, 2014

Conversation

hugohenrique
Copy link
Contributor

Removes requirement of the arguments in the constructor method and validates the method toArray if one of them was set.

In favor #615

@hugohenrique
Copy link
Contributor Author

ping @ruflin

'filter' => $this->_filter->toArray()
));
if ($this->_query === null && $this->_filter === null) {
throw new NotImplementedException('The query or filter have not been defined, you define at least one');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to use the not found exception here.

Also please use an exception per variable so it is clear, which one is missing for the developer using the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this point: "Also please use an exception per variable so it is clear, which one is missing for the developer using the library."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judging from the docs, both a query and filter are always required, so if one is missing the user needs to know which. Your message suggests it's possible to supply only one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mal Not! both unnecessary arguments and documentation shows that you can use both "query", "filter" or both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, you can save a comparison with something like;

    public function toArray()
    {
        $filtered = array();

        if ($this->_query !== null) {
            $filtered['query'] = $this->_query->toArray();
        }

        if ($this->_filter !== null) {
            $filtered['filter'] = $this->_filter->toArray();
        }

        if (empty($filtered)) {
            throw new NotFoundException('A query and/or filter is required');
        }

        return array('filtered' => $filtered);
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mal thanks for the suggestion!

@ruflin
Copy link
Owner

ruflin commented May 17, 2014

Yep, still here. Was just busy the last days. See comments. Can you also update the changes.txt file and add a test to make sure the changes work as expected?

@mal
Copy link
Contributor

mal commented May 17, 2014

Out of curiosity, I'd be interested to understand the use case for a FilteredQuery with no filter to apply to the query, or no query to be filtered?

@mal
Copy link
Contributor

mal commented May 17, 2014

Also; while trying to understand filtered queries a bit more; I tried this on ES1.1 and got valid results; so maybe a check/exception isn't needed at all ...

{
  "query": {
    "filtered": {}
  }
}

@hugohenrique
Copy link
Contributor Author

ping @ruflin

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) when pulling b8597a5 on hugohenrique:master into 58b0928 on ruflin:master.

@ruflin
Copy link
Owner

ruflin commented May 18, 2014

@hugohenrique Can you confirm what @mal just wrote above? Is only one of the two necessary? Please also update the changes.txt file.

$filtered['filter'] = $this->_filter->toArray();
}

if (empty($filtered)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the InvalidException here, as not implemented is used for features which were not implemented yet. But here the arguments are invalid.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) when pulling 9952a98 on hugohenrique:master into 58b0928 on ruflin:master.

@hugohenrique
Copy link
Contributor Author

ping @ruflin

@ruflin
Copy link
Owner

ruflin commented May 20, 2014

@hugohenrique Did you see my other two comments in the code?

@mal
Copy link
Contributor

mal commented May 20, 2014

Technically neither query, nor filter is required, it can in effect be empty, which seems to behave much like match_all.

@hugohenrique
Copy link
Contributor Author

@ruflin, I change some points, based in your suggestions, but others do not seed the need, you can reevaluate?

@ruflin
Copy link
Owner

ruflin commented May 23, 2014

@hugohenrique Will do on the weekend.

@ruflin
Copy link
Owner

ruflin commented May 24, 2014

I would prefer to check for the specific objects instead of null to make sure, it only gets executed when the proper object is set (which should be always the case). This means set a whiteliste instead of blacklist for the params. The good part about your solution is, that we would discover potential problems, if somehow someone sets the value to something where toArray doesn't work.

The Invalid exception looks good. The part I don't like is that it mixes the two error messages: "A query and/or filter is required". I would like the developer that uses the API exactly what is missing and what he has to add. As mentioned before, this adds a little bit more complexity on the client side, but in the end it simplifies the developers life.

@hugohenrique
Copy link
Contributor Author

Hi @ruflin,
Sorry my english could not understand your first question.
I think if you do your suggestions will be most appreciated!

@ruflin
Copy link
Owner

ruflin commented May 29, 2014

It was more of an input then a question. Instead of me changing it I think we should have a conversation on how to do it best.

My first comment is related to line number 102.

@hugohenrique
Copy link
Contributor Author

How can we end this?

@ruflin
Copy link
Owner

ruflin commented Jun 5, 2014

@hugohenrique There are 2 options. Either add a commit with the suggested changes or I will try to find some time this weekend to implement it :-)

@ruflin ruflin merged commit 9952a98 into ruflin:master Jun 14, 2014
@ruflin
Copy link
Owner

ruflin commented Jun 14, 2014

@hugohenrique I implemented my changes here and also added some tests: #636

@hugohenrique
Copy link
Contributor Author

Thanks @ruflin!

@ruflin
Copy link
Owner

ruflin commented Jun 15, 2014

Hm, I just realized I made an error during the implementation. At the end, also parent::toArray() should be called to make sure ->setParam('strategy', $strategy); for example works (which is not the case at the moment) :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants