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
-------
7d9bdf5734
Fixed deprecation warnings about passing null as parameter
This commit is contained in:
commit
eb3a3c1c0a
@ -151,9 +151,9 @@ if ('disabled' === $getEnvVar('SYMFONY_DEPRECATIONS_HELPER')) {
|
||||
}
|
||||
|
||||
$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar')
|
||||
|| ($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar 2> NUL`) : `which composer.phar 2> /dev/null`))
|
||||
|| ($COMPOSER = rtrim('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer 2> NUL`) : `which composer 2> /dev/null`))
|
||||
|| 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')
|
||||
|| ($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar 2> NUL`) : `which composer.phar 2> /dev/null`)))
|
||||
|| ($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer 2> NUL`) : `which composer 2> /dev/null`)))
|
||||
|| 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')
|
||||
? ('#!/usr/bin/env php' === file_get_contents($COMPOSER, false, null, 0, 18) ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
|
||||
: 'composer';
|
||||
|
||||
|
@ -46,7 +46,7 @@ class Cookie
|
||||
* Sets a cookie.
|
||||
*
|
||||
* @param string $name The cookie name
|
||||
* @param string $value The value of the cookie
|
||||
* @param string|null $value The value of the cookie
|
||||
* @param string|null $expires The time the cookie expires
|
||||
* @param string|null $path The path on the server in which the cookie will be available on
|
||||
* @param string $domain The domain that the cookie is available
|
||||
@ -62,7 +62,7 @@ class Cookie
|
||||
$this->rawValue = $value;
|
||||
} else {
|
||||
$this->value = $value;
|
||||
$this->rawValue = rawurlencode($value);
|
||||
$this->rawValue = rawurlencode($value ?? '');
|
||||
}
|
||||
$this->name = $name;
|
||||
$this->path = empty($path) ? '/' : $path;
|
||||
|
@ -157,7 +157,7 @@ class NodeExtension extends AbstractExtension
|
||||
{
|
||||
$element = $node->getElement();
|
||||
|
||||
if ($this->hasFlag(self::ELEMENT_NAME_IN_LOWER_CASE)) {
|
||||
if ($element && $this->hasFlag(self::ELEMENT_NAME_IN_LOWER_CASE)) {
|
||||
$element = strtolower($element);
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
|
||||
if ($value instanceof Definition) {
|
||||
$class = $value->getClass();
|
||||
|
||||
if (isset(self::BUILTIN_TYPES[strtolower($class)])) {
|
||||
if ($class && isset(self::BUILTIN_TYPES[strtolower($class)])) {
|
||||
$class = strtolower($class);
|
||||
} elseif (!$class || (!$this->autoload && !class_exists($class, false) && !interface_exists($class, false))) {
|
||||
return;
|
||||
|
@ -88,10 +88,12 @@ class RegisterServiceSubscribersPass extends AbstractRecursivePass
|
||||
$serviceMap[$key] = new Reference($type);
|
||||
}
|
||||
|
||||
if (false !== $i = strpos($name, '::get')) {
|
||||
$name = lcfirst(substr($name, 5 + $i));
|
||||
} elseif (false !== strpos($name, '::')) {
|
||||
$name = null;
|
||||
if ($name) {
|
||||
if (false !== $i = strpos($name, '::get')) {
|
||||
$name = lcfirst(substr($name, 5 + $i));
|
||||
} elseif (false !== strpos($name, '::')) {
|
||||
$name = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $name && !$this->container->has($name) && !$this->container->has($type.' $'.$name)) {
|
||||
|
@ -178,7 +178,7 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
|
||||
$typeHint = ProxyHelper::getTypeHint($reflectionMethod, $parameter);
|
||||
|
||||
if (\array_key_exists($k = ltrim($typeHint, '\\').' $'.$parameter->name, $bindings)) {
|
||||
if ($typeHint && \array_key_exists($k = ltrim($typeHint, '\\').' $'.$parameter->name, $bindings)) {
|
||||
$arguments[$key] = $this->getBindingValue($bindings[$k]);
|
||||
|
||||
continue;
|
||||
|
@ -47,7 +47,7 @@ abstract class AbstractUriElement
|
||||
$this->currentUri = $currentUri;
|
||||
|
||||
$elementUriIsRelative = null === parse_url(trim($this->getRawUri()), \PHP_URL_SCHEME);
|
||||
$baseUriIsAbsolute = \in_array(strtolower(substr($this->currentUri, 0, 4)), ['http', 'file']);
|
||||
$baseUriIsAbsolute = null !== $this->currentUri && \in_array(strtolower(substr($this->currentUri, 0, 4)), ['http', 'file']);
|
||||
if ($elementUriIsRelative && !$baseUriIsAbsolute) {
|
||||
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));
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ class NumberComparator extends Comparator
|
||||
*/
|
||||
public function __construct(?string $test)
|
||||
{
|
||||
if (!preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
|
||||
throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test));
|
||||
if (null === $test || !preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
|
||||
throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test ?? 'null'));
|
||||
}
|
||||
|
||||
$target = $matches[2];
|
||||
|
@ -124,7 +124,7 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
$args = [];
|
||||
foreach ($parameters as $p) {
|
||||
/** @var \ReflectionParameter $p */
|
||||
$type = ltrim($target = ProxyHelper::getTypeHint($r, $p), '\\');
|
||||
$type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\');
|
||||
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
|
||||
|
||||
if (isset($arguments[$r->name][$p->name])) {
|
||||
|
@ -164,7 +164,7 @@ class RouterListener implements EventSubscriberInterface
|
||||
private function createWelcomeResponse(): Response
|
||||
{
|
||||
$version = Kernel::VERSION;
|
||||
$projectDir = realpath($this->projectDir).\DIRECTORY_SEPARATOR;
|
||||
$projectDir = realpath((string) $this->projectDir).\DIRECTORY_SEPARATOR;
|
||||
$docVersion = substr(Kernel::VERSION, 0, 3);
|
||||
|
||||
ob_start();
|
||||
|
@ -212,8 +212,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testValidatesPrivateResponsesCachedOnTheClient()
|
||||
{
|
||||
$this->setNextResponse(200, [], '', function ($request, $response) {
|
||||
$etags = preg_split('/\s*,\s*/', $request->headers->get('IF_NONE_MATCH'));
|
||||
$this->setNextResponse(200, [], '', function (Request $request, $response) {
|
||||
$etags = preg_split('/\s*,\s*/', $request->headers->get('IF_NONE_MATCH', ''));
|
||||
if ($request->cookies->has('authenticated')) {
|
||||
$response->headers->set('Cache-Control', 'private, no-store');
|
||||
$response->setETag('"private tag"');
|
||||
|
@ -30,7 +30,7 @@ class AdapterTest extends LdapTestCase
|
||||
{
|
||||
$ldap = new Adapter();
|
||||
|
||||
$this->assertEquals('\20foo\3dbar\0d(baz)*\20', $ldap->escape(" foo=bar\r(baz)* ", null, LdapInterface::ESCAPE_DN));
|
||||
$this->assertEquals('\20foo\3dbar\0d(baz)*\20', $ldap->escape(" foo=bar\r(baz)* ", '', LdapInterface::ESCAPE_DN));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,7 +266,7 @@ class Email extends Message
|
||||
*/
|
||||
public function getPriority(): int
|
||||
{
|
||||
[$priority] = sscanf($this->getHeaders()->getHeaderBody('X-Priority'), '%[1-5]');
|
||||
[$priority] = sscanf($this->getHeaders()->getHeaderBody('X-Priority') ?? '', '%[1-5]');
|
||||
|
||||
return $priority ?? 3;
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
||||
|
||||
if (!$optional || $important || !\array_key_exists($varName, $defaults) || (null !== $mergedParams[$varName] && (string) $mergedParams[$varName] !== (string) $defaults[$varName])) {
|
||||
// check requirement (while ignoring look-around patterns)
|
||||
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
|
||||
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]] ?? '')) {
|
||||
if ($this->strictRequirements) {
|
||||
throw new InvalidParameterException(strtr($message, ['{parameter}' => $varName, '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$varName]]));
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ class LdapBindAuthenticationProviderTest extends TestCase
|
||||
->method('bind')
|
||||
->willThrowException(new ConnectionException())
|
||||
;
|
||||
$ldap->method('escape')->willReturnArgument(0);
|
||||
$userChecker = $this->createMock(UserCheckerInterface::class);
|
||||
|
||||
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
|
||||
@ -207,6 +208,7 @@ class LdapBindAuthenticationProviderTest extends TestCase
|
||||
->method('query')
|
||||
->willReturn($query)
|
||||
;
|
||||
$ldap->method('escape')->willReturnArgument(0);
|
||||
$userChecker = $this->createMock(UserCheckerInterface::class);
|
||||
|
||||
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap, '{username}', true, 'elsa', 'test1234A$');
|
||||
|
@ -82,8 +82,8 @@ class UsernamePasswordJsonAuthenticationListener extends AbstractListener implem
|
||||
|
||||
public function supports(Request $request): ?bool
|
||||
{
|
||||
if (false === strpos($request->getRequestFormat(), 'json')
|
||||
&& false === strpos($request->getContentType(), 'json')
|
||||
if (false === strpos($request->getRequestFormat() ?? '', 'json')
|
||||
&& false === strpos($request->getContentType() ?? '', 'json')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ class XliffFileLoader implements LoaderInterface
|
||||
private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, string $domain)
|
||||
{
|
||||
$xml = simplexml_import_dom($dom);
|
||||
$encoding = strtoupper($dom->encoding);
|
||||
$encoding = $dom->encoding ? strtoupper($dom->encoding) : null;
|
||||
|
||||
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0');
|
||||
|
||||
|
@ -507,7 +507,7 @@ EOF
|
||||
*/
|
||||
protected function assertValidLocale($locale)
|
||||
{
|
||||
if (1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
|
||||
if (null !== $locale && 1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid "%s" locale.', $locale));
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class IpValidator extends ConstraintValidator
|
||||
break;
|
||||
|
||||
default:
|
||||
$flag = null;
|
||||
$flag = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -616,7 +616,7 @@ class Parser
|
||||
$data = [];
|
||||
|
||||
if ($this->getCurrentLineIndentation() >= $newIndent) {
|
||||
$data[] = substr($this->currentLine, $newIndent);
|
||||
$data[] = substr($this->currentLine, $newIndent ?? 0);
|
||||
} elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
|
||||
$data[] = $this->currentLine;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user