10000 [HttpFoundation] Avoid implicit null to array conversion in request matcher by ro0NL · Pull Request #20275 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Avoid implicit null to array conversion in request matcher #20275

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 2 commits into from
Closed
Changes from all commits
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
26 changes: 13 additions & 13 deletions src/Symfony/Component/HttpFoundation/RequestMatcher.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
class RequestMatcher implements RequestMatcherInterface
{
/**
* @var string
* @var string|null
*/
private $path;

/**
* @var string
* @var string|null
*/
private $host;

/**
* @var array
* @var string[]
*/
private $methods = array();

/**
* @var string
* @var string[]
*/
private $ips = array();

Expand Down Expand Up @@ -76,13 +76,13 @@ public function __construct($path = null, $host = null, $methods = null, $ips =
*/
public function matchScheme($scheme)
{
$this->schemes = array_map('strtolower', (array) $scheme);
$this->schemes = null !== $scheme ? array_map('strtolower', (array) $scheme) : array();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really needed though. Confused with (array) null actually converting to an empty array, not something like array(null) :)

}

/**
* Adds a check for the URL host name.
*
* @param string $regexp A Regexp
* @param string|null $regexp A Regexp
*/
public function matchHost($regexp)
{
Expand All @@ -92,7 +92,7 @@ public function matchHost($regexp)
/**
* Adds a check for the URL path info.
*
* @param string $regexp A Regexp
* @param string|null $regexp A Regexp
*/
public function matchPath($regexp)
{
Expand All @@ -112,21 +112,21 @@ public function matchIp($ip)
/**
* Adds a check for the client IP.
*
* @param string|string[] $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
* @param string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
*/
public function matchIps($ips)
{
$this->ips = (array) $ips;
$this->ips = null !== $ips ? (array) $ips : array();
}

/**
* Adds a check for the HTTP method.
*
* @param string|string[] $method An HTTP method or an array of HTTP methods
* @param string|string[]|null $method An HTTP method or an array of HTTP methods
*/
public function matchMethod($method)
{
$this->methods = array_map('strtoupper', (array) $method);
$this->methods = null !== $method ? array_map('strtoupper', (array) $method) : array();
}

/**
Expand All @@ -145,11 +145,11 @@ public function matchAttribute($key, $regexp)
*/
public function matches(Request $request)
{
if ($this->schemes && !in_array($request->getScheme(), $this->schemes)) {
if ($this->schemes && !in_array($request->getScheme(), $this->schemes, true)) {
return false;
}

if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
if ($this->methods && !in_array($request->getMethod(), $this->methods, true)) {
return false;
}

Expand Down
0