Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Adds various return-typed getters to ParameterBag #49972

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

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make it using native calls
  • Loading branch information
mleczakm committed Apr 10, 2023
commit de83b1c5fe619401724479271cda178ec3dc28ae
6 changes: 3 additions & 3 deletions 6 src/Symfony/Component/HttpFoundation/ParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function getString(string $key, string $default = ''): string
public function getStringOrNull(string $key): ?string
{
return $this->has($key)
? $this->filter($key, null, \FILTER_DEFAULT, \FILTER_NULL_ON_FAILURE)
? $this->getString($key)
: null;
}

Expand All @@ -165,7 +165,7 @@ public function getInt(string $key, int $default = 0): int
public function getIntOrNull(string $key): ?int
{
return $this->has($key)
Copy link
Member

Choose a reason for hiding this comment

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

Checking if the value is set is not necessary:
filter_var(null, \FILTER_VALIDATE_INT, \FILTER_NULL_ON_FAILURE) returns null.

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've changed it to use getInt implementation instead.

? $this->filter($key, null, \FILTER_VALIDATE_INT, \FILTER_NULL_ON_FAILURE)
? $this->getInt($key)
: null;
}

Expand All @@ -180,7 +180,7 @@ public function getBoolean(string $key, bool $default = false): bool
public function getBooleanOrNull(string $key): ?bool
{
return $this->has($key)
? $this->filter($key, null, \FILTER_VALIDATE_BOOL, \FILTER_NULL_ON_FAILURE)
? $this->getBoolean($key)
: null;
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.