-
Notifications
You must be signed in to change notification settings - Fork 733
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
620c2b9
removes requirement of the arguments in the constructor method
hugohenrique 3aa2e8e
Condition was added to make not mandatory arguments
hugohenrique b1ec894
removed unnecessary checks in construct
hugohenrique ad8cf09
added the attribution of properties directly, without going through t…
hugohenrique b8597a5
added test when no argument is filled
hugohenrique ad5e377
replace NotImplementedException to InvalidException as suggestion by …
hugohenrique 551c5cc
update changes.txt
hugohenrique 9952a98
fix date changes.txt
hugohenrique File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
<?php | ||
|
||
namespace Elastica\Query; | ||
|
||
use Elastica\Filter\AbstractFilter; | ||
use Elastica\Exception\InvalidException; | ||
|
||
/** | ||
* Filtered query. Needs a query and a filter | ||
|
@@ -33,10 +35,12 @@ class Filtered extends AbstractQuery | |
* @param \Elastica\Query\AbstractQuery $query Query object | ||
* @param \Elastica\Filter\AbstractFilter $filter Filter object | ||
*/ | ||
public function __construct(AbstractQuery $query, AbstractFilter $filter) | ||
{ | ||
$this->setQuery($query); | ||
$this->setFilter($filter); | ||
public function __construct( | ||
AbstractQuery $query = null, | ||
AbstractFilter $filter = null | ||
) { | ||
$this->_query = $query; | ||
$this->_filter = $filter; | ||
} | ||
|
||
/** | ||
|
@@ -93,9 +97,20 @@ public function getQuery() | |
*/ | ||
public function toArray() | ||
{ | ||
return array('filtered' => array( | ||
'query' => $this->_query->toArray(), | ||
'filter' => $this->_filter->toArray() | ||
)); | ||
$filtered = array(); | ||
|
||
if ($this->_query !== null) { | ||
$filtered['query'] = $this->_query->toArray(); | ||
} | ||
|
||
if ($this->_filter !== null) { | ||
$filtered['filter'] = $this->_filter->toArray(); | ||
} | ||
|
||
if (empty($filtered)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
throw new InvalidException('A query and/or filter is required'); | ||
} | ||
|
||
return array('filtered' => $filtered); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking for not null, I would suggest to check if it is actually a Filter) (or above a query) as you did before in the constructor.