-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Make \Request::get
more performant.
#12369
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -723,7 +723,17 @@ public static function getHttpMethodParameterOverride() | |
*/ | ||
public function get($key, $default = null, $deep = false) | ||
{ | ||
return $this->query->get($key, $this->attributes->get($key, $this->request->get($key, $default, $deep), $deep), $deep); | ||
$result = $this->query->get($key, $this, $deep); | ||
if ($result === $this) { | ||
$result = $this->attributes->get($key, $this, $deep); | ||
} | ||
if ($result === $this) { | ||
$result = $this->request->get($key, $this, $deep); | ||
} | ||
if ($result === $this) { | ||
return $default; | ||
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. for the last one, you could pass the real default directly, using 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. we'd still need the last |
||
} | ||
return $result; | ||
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. I would have written it this way: if ($this !== $result = $this->query->get($key, $this, $deep)) {
return $result;
}
if ($this !== $result = $this->attributes->get($key, $this, $deep)) {
return $result;
}
if ($this !== $result = $this->request->get($key, $this, $deep)) {
return $result;
}
return $default; |
||
} | ||
|
||
/** | ||
|
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 would rather use the opposite conditions and using an early return rather than assigning
$result
over and over again inside conditions on it (which can be confusing when seeing a list ofif ($result === $this) {
conditions)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.
We'd still need to store them to a variable, the only difference is the return would be within each conditional. I'd rather have a single return no?