8000 bug #41240 Fixed deprecation warnings about passing null as parameter… · symfony/symfony@eb3a3c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb3a3c1

Browse files
committed
bug #41240 Fixed deprecation warnings about passing null as parameter (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- Fixed deprecation warnings about passing null as parameter | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Various built-in PHP functions will trigger a deprecation warning if `null` is passed as parameter. This PR attempts to fix all warnings that our test suite currently picks up. Commits ------- 7d9bdf5 Fixed deprecation warnings about passing null as parameter
2 parents 03519d4 + 7d9bdf5 commit eb3a3c1

File tree

20 files changed

+32
-28
lines changed

20 files changed

+32
-28
lines changed

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@
151151
}
152152

153153
$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar')
154-
|| ($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar 2> NUL`) : `which composer.phar 2> /dev/null`))
155-
|| ($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer 2> NUL`) : `which composer 2> /dev/null`))
156-
|| file_exists($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? `git rev-parse --show-toplevel 2> NUL` : `git rev-parse --show-toplevel 2> /dev/null`).\DIRECTORY_SEPARATOR.'composer.phar')
154+
|| ($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar 2> NUL`) : `which composer.phar 2> /dev/null`)))
155+
|| ($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer 2> NUL`) : `which composer 2> /dev/null`)))
156+
|| file_exists($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? `git rev-parse --show-toplevel 2> NUL` : `git rev-parse --show-toplevel 2> /dev/null`)).\DIRECTORY_SEPARATOR.'composer.phar')
157157
? ('#!/usr/bin/env php' === file_get_contents($COMPOSER, false, null, 0, 18) ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
158158
: 'composer';
159159

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Cookie
4646
* Sets a cookie.
4747
*
4848
* @param string $name The cookie name
49-
* @param string $value The value of the cookie
49+
* @param string|null $value The value of the cookie
5050
* @param string|null $expires The time the cookie expires
5151
* @param string|null $path The path on the server in which the cookie will be available on
5252
* @param string $domain The domain that the cookie is available
@@ -62,7 +62,7 @@ public function __construct(string $name, ?string $value, string $expires = null
6262
$this->rawValue = $value;
6363
} else {
6464
$this->value = $value;
65-
$this->rawValue = rawurlencode($value);
65+
$this->rawValue = rawurlencode($value ?? '');
6666
}
6767
$this->name = $name;
6868
$this->path = empty($path) ? '/' : $path;

src/Symfony/Component/CssSelector/XPath/Extension/NodeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function translateElement(Node\ElementNode $node): XPathExpr
157157
{
158158
$element = $node->getElement();
159159

160-
if ($this->hasFlag(self::ELEMENT_NAME_IN_LOWER_CASE)) {
160+
if ($element && $this->hasFlag(self::ELEMENT_NAME_IN_LOWER_CASE)) {
161161
$element = strtolower($element);
162162
}
163163

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
205205
if ($value instanceof Definition) {
206206
$class = $value->getClass();
207207

208-
if (isset(self::BUILTIN_TYPES[strtolower($class)])) {
208+
if ($class && isset(self::BUILTIN_TYPES[strtolower($class)])) {
209209
$class = strtolower($class);
210210
} elseif (!$class || (!$this->autoload && !class_exists($class, false) && !interface_exists($class, false))) {
211211
return;

src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ protected function processValue($value, $isRoot = false)
8888
$serviceMap[$key] = new Reference($type);
8989
}
9090

91-
if (false !== $i = strpos($name, '::get')) {
92-
$name = lcfirst(substr($name, 5 + $i));
93-
} elseif (false !== strpos($name, '::')) {
94-
$name = null;
91+
if ($name) {
92+
if (false !== $i = strpos($name, '::get')) {
93+
$name = lcfirst(substr($name, 5 + $i));
94+
} elseif (false !== strpos($name, '::')) {
95+
$name = null;
96+
}
9597
}
9698

9799
if (null !== $name && !$this->container->has($name) && !$this->container->has($type.' $'.$name)) {

src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected function processValue($value, $isRoot = false)
178178

179179
$typeHint = ProxyHelper::getTypeHint($reflectionMethod, $parameter);
180180

181-
if (\array_key_exists($k = ltrim($typeHint, '\\').' $'.$parameter->name, $bindings)) {
181+
if ($typeHint && \array_key_exists($k = ltrim($typeHint, '\\').' $'.$parameter->name, $bindings)) {
182182
$arguments[$key] = $this->getBindingValue($bindings[$k]);
183183

184184
continue;

src/Symfony/Component/DomCrawler/AbstractUriElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(\DOMElement $node, string $currentUri = null, ?strin
4747
$this->currentUri = $currentUri;
4848

4949
$elementUriIsRelative = null === parse_url(trim($this->getRawUri()), \PHP_URL_SCHEME);
50-
$baseUriIsAbsolute = \in_array(strtolower(substr($this->currentUri, 0, 4)), ['http', 'file']);
50+
$baseUriIsAbsolute = null !== $this->currentUri && \in_array(strtolower(substr($this->currentUri, 0, 4)), ['http', 'file']);
5151
if ($elementUriIsRelative && !$baseUriIsAbsolute) {
5252
throw new \InvalidArgumentException(sprintf('The URL of the element is relative, so you must define its base URI passing an absolute URL to the constructor of the "%s" class ("%s" was passed).', __CLASS__, $this->currentUri));
5353
}

src/Symfony/Component/Finder/Comparator/NumberComparator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class NumberComparator extends Comparator
4141
*/
4242
public function __construct(?string $test)
4343
{
44-
if (!preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
45-
throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test));
44+
if (null === $test || !preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
45+
throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test ?? 'null'));
4646
}
4747

4848
$target = $matches[2];

src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function process(ContainerBuilder $container)
124124
$args = [];
125125
foreach ($parameters as $p) {
126126
/** @var \ReflectionParameter $p */
127-
$type = ltrim($target = ProxyHelper::getTypeHint($r, $p), '\\');
127+
$type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\');
128128
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
129129

130130
if (isset($arguments[$r->name][$p->name])) {

src/Symfony/Component/HttpKernel/EventListener/RouterListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public static function getSubscribedEvents()
164164
private function createWelcomeResponse(): Response
165165
{
166166
$version = Kernel::VERSION;
167-
$projectDir = realpath($this->projectDir).\DIRECTORY_SEPARATOR;
167+
$projectDir = realpath((string) $this->projectDir).\DIRECTORY_SEPARATOR;
168168
$docVersion = substr(Kernel::VERSION, 0, 3);
169169

170170
ob_start();

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ public function testIncrementsMaxAgeWhenNoDateIsSpecifiedEventWhenUsingETag()
212212

213213
public function testValidatesPrivateResponsesCachedOnTheClient()
214214
{
215-
$this->setNextResponse(200, [], '', function ($request, $response) {
216-
$etags = preg_split('/\s*,\s*/', $request->headers->get('IF_NONE_MATCH'));
215+
$this->setNextResponse(200, [], '', function (Request $request, $response) {
216+
$etags = preg_split('/\s*,\s*/', $request->headers->get('IF_NONE_MATCH', ''));
217217
if ($request->cookies->has('authenticated')) {
218218
$response->headers->set('Cache-Control', 'private, no-store');
219219
$response->setETag('"private tag"');

src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testLdapEscape()
3030
{
3131
$ldap = new Adapter();
3232

33-
$this->assertEquals('\20foo\3dbar\0d(baz)*\20', $ldap->escape(" foo=bar\r(baz)* ", null, LdapInterface::ESCAPE_DN));
33+
$this->assertEquals('\20foo\3dbar\0d(baz)*\20', $ldap->escape(" foo=bar\r(baz)* ", '', LdapInterface::ESCAPE_DN));
3434
}
3535

3636
/**

src/Symfony/Component/Mime/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public function priority(int $priority)
266266
*/
267267
public function getPriority(): int
268268
{
269-
[$priority] = sscanf($this->getHeaders()->getHeaderBody('X-Priority'), '%[1-5]');
269+
[$priority] = sscanf($this->getHeaders()->getHeaderBody('X-Priority') ?? '', '%[1-5]');
270270

271271
return $priority ?? 3;
< 10000 code>272272
}

src/Symfony/Component/Routing/Generator/UrlGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
188188

189189
if (!$optional || $important || !\array_key_exists($varName, $defaults) || (null !== $mergedParams[$varName] && (string) $mergedParams[$varName] !== (string) $defaults[$varName])) {
190190
// check requirement (while ignoring look-around patterns)
191-
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
191+
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]] ?? '')) {
192192
if ($this->strictRequirements) {
193193
throw new InvalidParameterException(strtr($message, ['{parameter}' => $varName, '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$varName]]));
194194
}

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function testBindFailureShouldThrowAnException()
7070
->method('bind')
7171
->willThrowException(new ConnectionException())
7272
;
73+
$ldap->method('escape')->willReturnArgument(0);
7374
$userChecker = $this->createMock(UserCheckerInterface::class);
7475

7576
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
@@ -207,6 +208,7 @@ public function testEmptyQueryResultShouldThrowAnException()
207208
->method('query')
208209
->willReturn($query)
209210
;
211+
$ldap->method('escape')->willReturnArgument(0);
210212
$userChecker = $this->createMock(UserCheckerInterface::class);
211213

212214
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap, '{username}', true, 'elsa', 'test1234A$');

src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
8282

8383
public function supports(Request $request): ?bool
8484
{
85-
if (false === strpos($request->getRequestFormat(), 'json')
86-
&& false === strpos($request->getContentType(), 'json')
85+
if (false === strpos($request->getRequestFormat() ?? '', 'json')
86+
&& false === strpos($request->getContentType() ?? '', 'json')
8787
) {
8888
return false;
8989
}

src/Symfony/Component/Translation/Loader/XliffFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, s
129129
private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, string $domain)
130130
{
131131
$xml = simplexml_import_dom($dom);
132-
$encoding = strtoupper($dom->encoding);
132+
$encoding = $dom->encoding ? strtoupper($dom->encoding) : null;
133133

134134
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0');
135135

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ protected function computeFallbackLocales($locale)
507507
*/
508508
protected function assertValidLocale($locale)
509509
{
510-
if (1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
510+
if (null !== $locale && 1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
511511
throw new InvalidArgumentException(sprintf('Invalid "%s" locale.', $locale));
512512
}
513513
}

src/Symfony/Component/Validator/Constraints/IpValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function validate($value, Constraint $constraint)
9393
break;
9494

9595
default:
96-
$flag = null;
96+
$flag = 0;
9797
break;
9898
}
9999

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f
616616
$data = [];
617617

618618
if ($this->getCurrentLineIndentation() >= $newIndent) {
619-
$data[] = substr($this->currentLine, $newIndent);
619+
$data[] = substr($this->currentLine, $newIndent ?? 0);
620620
} elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
621621
$data[] = $this->currentLine;
622622
} else {

0 commit comments

Comments
 (0)
0