10000 minor #20275 [HttpFoundation] Avoid implicit null to array conversion… · symfony/symfony@fd1ee25 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd1ee25

Browse files
committed
minor #20275 [HttpFoundation] Avoid implicit null to array conversion in request matcher (ro0NL)
This PR was squashed before being merged into the 2.7 branch (closes #20275). Discussion ---------- [HttpFoundation] Avoid implicit null to array conversion in request matcher | Q | A | | --- | --- | | Branch? | 2.7 | | Bug fix? | yes | | New feature? | no | | BC breaks? | no | | Deprecations? | no | | Tests pass? | yes | | Fixed tickets | comma-separated list of tickets fixed by the PR, if any | | License | MIT | | Doc PR | reference to the documentation PR, if any | `null` is allowed _and_ passed as default value from the constructor. Lets be explicit. Commits ------- a2c0a78 [HttpFoundation] Avoid implicit null to array conversion in request matcher
2 parents 2b0c863 + a2c0a78 commit fd1ee25

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/Symfony/Component/HttpFoundation/RequestMatcher.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
class RequestMatcher implements RequestMatcherInterface
2020
{
2121
/**
22-
* @var string
22+
* @var string|null
2323
*/
2424
private $path;
2525

2626
/**
27-
* @var string
27+
* @var string|null
2828
*/
2929
private $host;
3030

3131
/**
32-
* @var array
32+
* @var string[]
3333
*/
3434
private $methods = array();
3535

3636
/**
37-
* @var string
37+
* @var string[]
3838
*/
3939
private $ips = array();
4040

@@ -76,13 +76,13 @@ public function __construct($path = null, $host = null, $methods = null, $ips =
7676
*/
7777
public function matchScheme($scheme)
7878
{
79-
$this->schemes = array_map('strtolower', (array) $scheme);
79+
$this->schemes = null !== $scheme ? array_map('strtolower', (array) $scheme) : array();
8080
}
8181

8282
/**
8383
* Adds a check for the URL host name.
8484
*
85-
* @param string $regexp A Regexp
85+
* @param string|null $regexp A Regexp
8686
*/
8787
public function matchHost($regexp)
8888
{
@@ -92,7 +92,7 @@ public function matchHost($regexp)
9292
/**
9393
* Adds a check for the URL path info.
9494
*
95-
* @param string $regexp A Regexp
95+
* @param string|null $regexp A Regexp
9696
*/
9797
public function matchPath($regexp)
9898
{
@@ -112,21 +112,21 @@ public function matchIp($ip)
112112
/**
113113
* Adds a check for the client IP.
114114
*
115-
* @param string|string[] $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
115+
* @param string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
116116
*/
117117
public function matchIps($ips)
118118
{
119-
$this->ips = (array) $ips;
119+
$this->ips = null !== $ips ? (array) $ips : array();
120120
}
121121

122122
/**
123123
* Adds a check for the HTTP method.
124124
*
125-
* @param string|string[] $method An HTTP method or an array of HTTP methods
125+
* @param string|string[]|null $method An HTTP method or an array of HTTP methods
126126
*/
127127
public function matchMethod($method)
128128
{
129-
$this->methods = array_map('strtoupper', (array) $method);
129+
$this->methods = null !== $method ? array_map('strtoupper', (array) $method) : array();
130130
}
131131

132132
/**
@@ -145,11 +145,11 @@ public function matchAttribute($key, $regexp)
145145
*/
146146
public function matches(Request $request)
147147
{
148-
if ($this->schemes && !in_array($request->getScheme(), $this->schemes)) {
148+
if ($this->schemes && !in_array($request->getScheme(), $this->schemes, true)) {
149149
return false;
150150
}
151151

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

0 commit comments

Comments
 (0)
0