Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  [HttpFoundation] Allow array style callable setting for Request setFactory method
  Make more nullable types explicit
  Add more explicit nullable types for default null values
  • Loading branch information
derrabus committed Mar 19, 2024
2 parents 9ba818e + ce5447b commit fb28944
Show file tree
Hide file tree
Showing 44 changed files with 108 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public function testBaselineFileWriteError()
$this->expectException(\ErrorException::class);
$this->expectExceptionMessageMatches('/[Ff]ailed to open stream: Permission denied/');

set_error_handler(static function (int $errno, string $errstr, string $errfile = null, int $errline = null): bool {
set_error_handler(static function (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null): bool {
if ($errno & (E_WARNING | E_WARNING)) {
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
use Symfony\Component\DependencyInjection\Tests\Fixtures\OptionalParameter;
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTarget;
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTargetAnonymous;
use Symfony\Component\DependencyInjection\TypedReference;
Expand Down Expand Up @@ -399,6 +400,9 @@ public function testResolveParameter()
$this->assertEquals(Foo::class, $container->getDefinition('bar')->getArgument(0));
}

/**
* @group legacy
*/
public function testOptionalParameter()
{
$container = new ContainerBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class Bar implements BarInterface
{
public $quz;

public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = [], iterable $baz = [])
public function __construct($quz = null, ?\NonExistent $nonExistent = null, ?BarInterface $decorated = null, array $foo = [], iterable $baz = [])
{
$this->quz = $quz;
}

public static function create(\NonExistent $nonExistent = null, $factory = null)
public static function create(?\NonExistent $nonExistent = null, $factory = null)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function setFoosVariadic(Foo $foo, Foo ...$foos)
$this->foo = $foo;
}

public function setFoosOptional(Foo $foo, Foo $fooOptional = null)
public function setFoosOptional(Foo $foo, ?Foo $fooOptional = null)
{
$this->foo = $foo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BarOptionalArgument
{
public $foo;

public function __construct(\stdClass $foo = null)
public function __construct(?\stdClass $foo = null)
{
$this->foo = $foo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static function createBar()
return new Bar(new \stdClass());
}

public static function createBarArguments(\stdClass $stdClass, \stdClass $stdClassOptional = null)
public static function createBarArguments(\stdClass $stdClass, ?\stdClass $stdClassOptional = null)
{
return new Bar($stdClass);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Tests\Fixtures;

use Symfony\Component\DependencyInjection\Tests\Compiler\A;
use Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface;
use Symfony\Component\DependencyInjection\Tests\Compiler\Foo;

class OptionalParameter
{
public function __construct(?CollisionInterface $c = null, A $a, ?Foo $f = null)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#[When(env: 'dev')]
class Foo implements FooInterface, Sub\BarInterface
{
public function __construct($bar = null, iterable $foo = null, object $baz = null)
public function __construct($bar = null, ?iterable $foo = null, ?object $baz = null)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function __construct(A $a, DInterface $d)

class E
{
public function __construct(D $d = null)
public function __construct(?D $d = null)
{
}
}
Expand Down Expand Up @@ -162,13 +162,6 @@ public function __construct(Dunglas $j, Dunglas $k)
}
}

class OptionalParameter
{
public function __construct(CollisionInterface $c = null, A $a, Foo $f = null)
{
}
}

class BadTypeHintedArgument
{
public function __construct(Dunglas $k, NotARealClass $r)
Expand Down Expand Up @@ -202,7 +195,7 @@ public function __construct(A $k, $foo, Dunglas $dunglas, array $bar)

class MultipleArgumentsOptionalScalar
{
public function __construct(A $a, $foo = 'default_val', Lille $lille = null)
public function __construct(A $a, $foo = 'default_val', ?Lille $lille = null)
{
}
}
Expand All @@ -226,7 +219,7 @@ public function __construct(
*/
class ClassForResource
{
public function __construct($foo, Bar $bar = null)
public function __construct($foo, ?Bar $bar = null)
{
}

Expand Down Expand Up @@ -345,7 +338,7 @@ public function setBar()
{
}

public function setOptionalNotAutowireable(NotARealClass $n = null)
public function setOptionalNotAutowireable(?NotARealClass $n = null)
{
}

Expand Down Expand Up @@ -392,7 +385,7 @@ class DecoratorImpl implements DecoratorInterface

class Decorated implements DecoratorInterface
{
public function __construct($quz = null, \NonExistent $nonExistent = null, DecoratorInterface $decorated = null, array $foo = [])
public function __construct($quz = null, ?\NonExistent $nonExistent = null, ?DecoratorInterface $decorated = null, array $foo = [])
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public function fooMethod(string $foo)
/**
* @param string $bar parameter not implemented yet
*/
public function barMethod(/* string $bar = null */)
public function barMethod(/* ?string $bar = null */)
{
}

/**
* @param Quz $quz parameter not implemented yet
*/
public function quzMethod(/* Quz $quz = null */)
public function quzMethod(/* ?Quz $quz = null */)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MockStream
* @param string|null $opened_path If the path is opened successfully, and STREAM_USE_PATH is set in options,
* opened_path should be set to the full path of the file/resource that was actually opened
*/
public function stream_open(string $path, string $mode, int $options, string &$opened_path = null): bool
public function stream_open(string $path, string $mode, int $options, ?string &$opened_path = null): bool
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable
{
private array $array;

public function __construct(array $array = null)
public function __construct(?array $array = null)
{
$this->array = $array ?: [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(array $translations)
$this->translations = $translations;
}

public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string
{
return $this->translations[$id] ?? $id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static function create(string $uri, string $method = 'GET', array $parame
*/
public static function setFactory(?callable $callable): void
{
self::$requestFactory = $callable;
self::$requestFactory = null === $callable ? null : $callable(...);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,23 @@ public function testFactory()
Request::setFactory(null);
}

public function testFactoryCallable()
{
$requestFactory = new class {
public function createRequest(): Request
{
return new NewRequest();
}
};

Request::setFactory([$requestFactory, 'createRequest']);

$this->assertEquals('foo', Request::create('/')->getFoo());

Request::setFactory(null);

}

/**
* @dataProvider getLongHostNames
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct($varToClone)
$this->varToClone = $varToClone;
}

public function collect(Request $request, Response $response, \Throwable $exception = null): void
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
$this->data = $this->cloneVar($this->varToClone);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface BatchHandlerInterface
* @return mixed The number of pending messages in the batch if $ack is not null,
* the result from handling the message otherwise
*/
// public function __invoke(object $message, Acknowledger $ack = null): mixed;
// public function __invoke(object $message, ?Acknowledger $ack = null): mixed;

/**
* Flushes any pending buffers.
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ CHANGELOG

* The bridge is not marked as `@experimental` anymore
* [BC BREAK] Change signature of `EsendexTransport::__construct()` method from:
`public function __construct(string $token, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
`public function __construct(string $token, string $accountReference, string $from, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)`
to:
`public function __construct(string $email, string $password, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
`public function __construct(string $email, string $password, string $accountReference, string $from, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)`

5.2.0
-----
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ CHANGELOG
* The bridge is not marked as `@experimental` anymore
* [BC BREAK] Remove `GoogleChatTransport::setThreadKey()` method, this parameter should now be provided via the constructor,
which has changed from:
`__construct(string $space, string $accessKey, string $accessToken, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
`__construct(string $space, string $accessKey, string $accessToken, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)`
to:
`__construct(string $space, string $accessKey, string $accessToken, string $threadKey = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
`__construct(string $space, string $accessKey, string $accessToken, ?string $threadKey = null, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)`
* [BC BREAK] Rename the parameter `threadKey` to `thread_key` in DSN

5.2.0
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Notifier/Bridge/Mattermost/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ CHANGELOG

* The bridge is not marked as `@experimental` anymore
* [BC BREAK] Change signature of `MattermostTransport::__construct()` method from:
`public function __construct(string $token, string $channel, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, string $path = null)`
`public function __construct(string $token, string $channel, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null, ?string $path = null)`
to:
`public function __construct(string $token, string $channel, ?string $path = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
`public function __construct(string $token, string $channel, ?string $path = null, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)`

5.1.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NonTraversableArrayObject implements \ArrayAccess, \Countable
{
private $array;

public function __construct(array $array = null)
public function __construct(?array $array = null)
{
$this->array = $array ?: [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TraversableArrayObject implements \ArrayAccess, \IteratorAggregate, \Count
{
private $array;

public function __construct(array $array = null)
public function __construct(?array $array = null)
{
$this->array = $array ?: [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private function getMutatorMethod(string $class, string $property): ?array
continue;
}

// Parameter can be optional to allow things like: method(array $foo = null)
// Parameter can be optional to allow things like: method(?array $foo = null)
if ($reflectionMethod->getNumberOfParameters() >= 1) {
return [$reflectionMethod, $prefix];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function getA()
*
* @param ParentDummy|null $parent
*/
public function setB(ParentDummy $parent = null)
public function setB(?ParentDummy $parent = null)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
{
public function redirect(string $path, string $route, string $scheme = null): array
public function redirect(string $path, string $route, ?string $scheme = null): array
{
return [
'_controller' => 'Some controller reference...',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public function getAllowedAttributes(string|object $classOrObject, array $contex
return parent::getAllowedAttributes($classOrObject, $context, $attributesAsString);
}

public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
{
}

public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return true;
}

public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
{
}

public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class DenormalizableDummy implements DenormalizableInterface
{
public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, string $format = null, array $context = []): void
public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, ?string $format = null, array $context = []): void
{
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Dummy implements NormalizableInterface, DenormalizableInterface
public $baz;
public $qux;

public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []): array|string|int|float|bool
public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = []): array|string|int|float|bool
{
return [
'foo' => $this->foo,
Expand All @@ -33,7 +33,7 @@ public function normalize(NormalizerInterface $normalizer, string $format = null
];
}

public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, string $format = null, array $context = []): void
public function denormalize(DenormalizerInterface $denormalizer, array|string|int|float|bool $data, ?string $format = null, array $context = []): void
{
$this->foo = $data['foo'];
$this->bar = $data['bar'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DummyString implements DenormalizableInterface
/** @var string $value */
public $value;

public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []): void
public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = []): void
{
$this->value = $data;
}
Expand Down

0 comments on commit fb28944

Please sign in to comment.