-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Apply filter even if the operator is not provided #6591
Apply filter even if the operator is not provided #6591
Conversation
1884f0d
to
0d1b1d9
Compare
src/Datagrid/Datagrid.php
Outdated
('' !== $this->values[$filterFormName]['type'] || '' !== $this->values[$filterFormName]['value']) | ||
) { | ||
|
||
$hasValue = isset($this->values[$filterFormName]['value']) |
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.
May be extract some methods here?
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.
IMHO there is too much private method here.
Testing applyFilter
wasn't easy.
Creating one method for a one line check seems overkill.
I already use one time variable for improving the readability.
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.
IMHO there is too much private method here.
That's an other problem of the class. The class / method does too much stuff.
Creating one method for a one line check seems overkill.
Not, if you look at the NPath complexity here...
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.
Not, if you look at the NPath complexity here...
I don't see why it would improve the complexity.
What method do you want to extract ?
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.
I think @core23 probably means to have a hasType
and hasValue
method, or just one method with an extra 'value'|'type'
parameter
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.
Yes but it's basically a method
private function hasValue($key1, $key2)
{
return isset($this->values[$key1][$key2]) && '' !== $this->values[$key1][$key2];
}
used this way
if ($this->hasValue($filterFormName, 'value') || $this->hasValue($filterFormName, 'type')) {
$filter->apply($this->query, $data[$filterFormName]);
}
I don't understand how it improved the complexity. I just feel like it's loosing context.
I changed the code for
$value = $this->values[$filterFormName]['value'] ?? '';
$type = $this->values[$filterFormName]['type'] ?? '';
if ('' !== $value || '' !== $type) {
$filter->apply($this->query, $data[$filterFormName]);
}
Isn't it better ?
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.
That looks good enough to me 👍
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.
My 2 cents, maybe giving some semantic to the method, something like:
foreach ($this->getFilters() as $name => $filter) {
$this->values[$name] = $this->values[$name] ?? null;
if ($this->canFilterBeApplied($filter, $this->values)) {
$filter->apply($this->query, $data[$filterFormName]);
}
}
Maybe there should be a method in FilterInterface
to check if a filter can be applied or not.
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.
I'm more concern about the line
$this->values[$name] = $this->values[$name] ?? null;
Which I don't understand.
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.
But the purpose of this PR is to fix a bug, so I would avoid to introduce a new method in the interface or to remove a line I don't understand here, in order to quickly release a 3.80.1 version.
0d1b1d9
to
09abd06
Compare
09abd06
to
62ed7c9
Compare
62ed7c9
to
6dc0b93
Compare
Subject
Bug reported #6590
I am targeting this branch, because bug fix.
Changelog