Skip to content

Commit 9298af4

Browse files
Add union types
1 parent d9f0467 commit 9298af4

File tree

199 files changed

+384
-566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+384
-566
lines changed

src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,7 @@ private function initializeSubscribers()
207207
$this->subscribers = [];
208208
}
209209

210-
/**
211-
* @param string|object $listener
212-
*/
213-
private function getHash($listener): string
210+
private function getHash(string | object $listener): string
214211
{
215212
if (\is_string($listener)) {
216213
return '_service_'.$listener;
@@ -219,10 +216,7 @@ private function getHash($listener): string
219216
return spl_object_hash($listener);
220217
}
221218

222-
/**
223-
* @param object $listener
224-
*/
225-
private function getMethod($listener, string $event): string
219+
private function getMethod(object $listener, string $event): string
226220
{
227221
if (!method_exists($listener, $event) && method_exists($listener, '__invoke')) {
228222
return '__invoke';

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function createChoiceLabel(object $choice): string
7373
* @internal This method is public to be usable as callback. It should not
7474
* be used in user code.
7575
*/
76-
public static function createChoiceName(object $choice, $key, string $value): string
76+
public static function createChoiceName(object $choice, int | string $key, string $value): string
7777
{
7878
return str_replace('-', '_', (string) $value);
7979
}
@@ -92,7 +92,7 @@ public static function createChoiceName(object $choice, $key, string $value): st
9292
* @internal This method is public to be usable as callback. It should not
9393
* be used in user code.
9494
*/
95-
public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array
95+
public function getQueryBuilderPartsForCachingHash(object $queryBuilder): ?array
9696
{
9797
return null;
9898
}

src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getBlockPrefix()
7676
* @internal This method is public to be usable as callback. It should not
7777
* be used in user code.
7878
*/
79-
public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array
79+
public function getQueryBuilderPartsForCachingHash(object $queryBuilder): ?array
8080
{
8181
if (!$queryBuilder instanceof QueryBuilder) {
8282
throw new \TypeError(sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, get_debug_type($queryBuilder)));

src/Symfony/Bridge/Twig/Extension/FormExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private function createFieldTranslation(?string $value, array $parameters, $doma
193193
*
194194
* @see ChoiceView::isSelected()
195195
*/
196-
function twig_is_selected_choice(ChoiceView $choice, $selectedValue): bool
196+
function twig_is_selected_choice(ChoiceView $choice, string | array $selectedValue): bool
197197
{
198198
if (\is_array($selectedValue)) {
199199
return \in_array($choice->value, $selectedValue, true);

src/Symfony/Bridge/Twig/Extension/HttpKernelRuntime.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(FragmentHandler $handler, FragmentUriGeneratorInterf
3838
*
3939
* @see FragmentHandler::render()
4040
*/
41-
public function renderFragment($uri, array $options = []): string
41+
public function renderFragment(string | ControllerReference $uri, array $options = []): string
4242
{
4343
$strategy = $options['strategy'] ?? 'inline';
4444
unset($options['strategy']);
@@ -53,7 +53,7 @@ public function renderFragment($uri, array $options = []): string
5353
*
5454
* @see FragmentHandler::render()
5555
*/
56-
public function renderFragmentStrategy(string $strategy, $uri, array $options = []): string
56+
public function renderFragmentStrategy(string $strategy, string | ControllerReference $uri, array $options = []): string
5757
{
5858
return $this->handler->render($uri, $strategy, $options);
5959
}

src/Symfony/Bridge/Twig/Extension/TranslationExtension.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ public function getTranslationNodeVisitor(): TranslationNodeVisitor
106106
}
107107

108108
/**
109-
* @param string|\Stringable|TranslatableInterface|null $message
110-
* @param array|string $arguments Can be the locale as a string when $message is a TranslatableInterface
109+
* @param array|string $arguments Can be the locale as a string when $message is a TranslatableInterface
111110
*/
112-
public function trans($message, $arguments = [], string $domain = null, string $locale = null, int $count = null): string
111+
public function trans(string | \Stringable | TranslatableInterface | null $message, array | string $arguments = [], string $domain = null, string $locale = null, int $count = null): string
113112
{
114113
if ($message instanceof TranslatableInterface) {
115114
if ([] !== $arguments && !\is_string($arguments)) {

src/Symfony/Bridge/Twig/Mime/NotificationEmail.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,10 @@ public function importance(string $importance)
124124
}
125125

126126
/**
127-
* @param \Throwable|FlattenException $exception
128-
*
129127
* @return $this
130128
*/
131-
public function exception($exception)
129+
public function exception(\Throwable | FlattenException $exception)
132130
{
133-
if (!$exception instanceof \Throwable && !$exception instanceof FlattenException) {
134-
throw new \LogicException(sprintf('"%s" accepts "%s" or "%s" instances.', __METHOD__, \Throwable::class, FlattenException::class));
135-
}
136-
137131
$exceptionAsString = $this->getExceptionAsString($exception);
138132

139133
$this->context['exception'] = true;

src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
*/
2929
abstract class AbstractConfigCommand extends ContainerDebugCommand
3030
{
31-
/**
32-
* @param OutputInterface|StyleInterface $output
33-
*/
34-
protected function listBundles($output)
31+
protected function listBundles(OutputInterface | StyleInterface $output)
3532
{
3633
$title = 'Available registered bundles with their extension alias if available';
3734
$headers = ['Bundle name', 'Extension alias'];

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ abstract protected function describeContainerTags(ContainerBuilder $builder, arr
113113
*
114114
* @param Definition|Alias|object $service
115115
*/
116-
abstract protected function describeContainerService($service, array $options = [], ContainerBuilder $builder = null);
116+
abstract protected function describeContainerService(object $service, array $options = [], ContainerBuilder $builder = null);
117117

118118
/**
119119
* Describes container services.

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio
6767
$this->writeData($data, $options);
6868
}
6969

70-
protected function describeContainerService($service, array $options = [], ContainerBuilder $builder = null)
70+
protected function describeContainerService(object $service, array $options = [], ContainerBuilder $builder = null)
7171
{
7272
if (!isset($options['id'])) {
7373
throw new \InvalidArgumentException('An "id" option must be provided.');

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio
8888
}
8989
}
9090

91-
protected function describeContainerService($service, array $options = [], ContainerBuilder $builder = null)
91+
protected function describeContainerService(object $service, array $options = [], ContainerBuilder $builder = null)
9292
{
9393
if (!isset($options['id'])) {
9494
throw new \InvalidArgumentException('An "id" option must be provided.');

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio
141141
}
142142
}
143143

144-
protected function describeContainerService($service, array $options = [], ContainerBuilder $builder = null)
144+
protected function describeContainerService(object $service, array $options = [], ContainerBuilder $builder = null)
145145
{
146146
if (!isset($options['id'])) {
147147
throw new \InvalidArgumentException('An "id" option must be provided.');

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function describeContainerTags(ContainerBuilder $builder, array $optio
5353
$this->writeDocument($this->getContainerTagsDocument($builder, isset($options['show_hidden']) && $options['show_hidden']));
5454
}
5555

56-
protected function describeContainerService($service, array $options = [], ContainerBuilder $builder = null)
56+
protected function describeContainerService(object $service, array $options = [], ContainerBuilder $builder = null)
5757
{
5858
if (!isset($options['id'])) {
5959
throw new \InvalidArgumentException('An "id" option must be provided.');

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected function json($data, int $status = 200, array $headers = [], array $co
186186
*
187187
* @param \SplFileInfo|string $file File object or path to file to be sent as response
188188
*/
189-
protected function file($file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse
189+
protected function file(\SplFileInfo | string $file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse
190190
{
191191
$response = new BinaryFileResponse($file);
192192
$response->setContentDisposition($disposition, null === $fileName ? $response->getFile()->getFilename() : $fileName);

src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(UrlGeneratorInterface $router = null, int $httpPort
5454
*
5555
* @throws HttpException In case the route name is empty
5656
*/
57-
public function redirectAction(Request $request, string $route, bool $permanent = false, $ignoreAttributes = false, bool $keepRequestMethod = false, bool $keepQueryParams = false): Response
57+
public function redirectAction(Request $request, string $route, bool $permanent = false, bool | array $ignoreAttributes = false, bool $keepRequestMethod = false, bool $keepQueryParams = false): Response
5858
{
5959
if ('' == $route) {
6060
throw new HttpException($permanent ? 410 : 404);

src/Symfony/Component/BrowserKit/AbstractBrowser.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public function request(string $method, string $uri, array $parameters = [], arr
441441
*
442442
* @throws \RuntimeException When processing returns exit code
443443
*/
444-
protected function doRequestInProcess($request)
444+
protected function doRequestInProcess(object $request)
445445
{
446446
$deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
447447
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
@@ -476,7 +476,7 @@ protected function doRequestInProcess($request)
476476
*
477477
* @return object An origin response instance
478478
*/
479-
abstract protected function doRequest($request);
479+
abstract protected function doRequest(object $request);
480480

481481
/**
482482
* Returns the script to execute when the request must be insulated.
@@ -485,7 +485,7 @@ abstract protected function doRequest($request);
485485
*
486486
* @throws \LogicException When this abstract class is not implemented
487487
*/
488-
protected function getScript($request)
488+
protected function getScript(object $request)
489489
{
490490
throw new \LogicException('To insulate requests, you need to override the getScript() method.');
491491
}
@@ -507,7 +507,7 @@ protected function filterRequest(Request $request)
507507
*
508508
* @return Response An BrowserKit Response instance
509509
*/
510-
protected function filterResponse($response)
510+
protected function filterResponse(object $response)
511511
{
512512
return $response;
513513
}
@@ -699,7 +699,7 @@ protected function getAbsoluteUri(string $uri)
699699
*
700700
* @return Crawler
701701
*/
702-
protected function requestFromRequest(Request $request, $changeHistory = true)
702+
protected function requestFromRequest(Request $request, bool $changeHistory = true)
703703
{
704704
return $this->request($request->getMethod(), $request->getUri(), $request->getParameters(), $request->getFiles(), $request->getServer(), $request->getContent(), $changeHistory);
705705
}

src/Symfony/Component/BrowserKit/HttpBrowser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(HttpClientInterface $client = null, History $history
4242
/**
4343
* @param Request $request
4444
*/
45-
protected function doRequest($request): Response
45+
protected function doRequest(object $request): Response
4646
{
4747
$headers = $this->getHeaders($request);
4848
[$body, $extraHeaders] = $this->getBodyAndExtraHeaders($request, $headers);

src/Symfony/Component/BrowserKit/Tests/TestClient.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function setNextScript($script)
2929
$this->nextScript = $script;
3030
}
3131

32-
protected function doRequest($request): Response
32+
protected function doRequest(object $request): Response
3333
{
3434
if (null === $this->nextResponse) {
3535
return new Response();
@@ -41,7 +41,7 @@ protected function doRequest($request): Response
4141
return $response;
4242
}
4343

44-
protected function getScript($request)
44+
protected function getScript(object $request)
4545
{
4646
$r = new \ReflectionClass(Response::class);
4747
$path = $r->getFileName();

src/Symfony/Component/BrowserKit/Tests/TestHttpClient.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function setNextScript($script)
5252
$this->nextScript = $script;
5353
}
5454

55-
protected function doRequest($request): Response
55+
protected function doRequest(object $request): Response
5656
{
5757
if (null === $this->nextResponse) {
5858
return parent::doRequest($request);
@@ -64,7 +64,7 @@ protected function doRequest($request): Response
6464
return $response;
6565
}
6666

67-
protected function getScript($request)
67+
protected function getScript(object $request)
6868
{
6969
$r = new \ReflectionClass(Response::class);
7070
$path = $r->getFileName();

src/Symfony/Component/Cache/CacheItem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function getMetadata(): array
151151
/**
152152
* Validates a cache key according to PSR-6.
153153
*
154-
* @param string $key The key to validate
154+
* @param mixed $key The key to validate
155155
*
156156
* @throws InvalidArgumentException When $key is not valid
157157
*/

src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,12 @@ public function saveDeferred(CacheItemInterface $item)
291291
*
292292
* Calling this method also clears the memoized namespace version and thus forces a resynchonization of it.
293293
*
294-
* @param bool $enable
295-
*
296294
* @return bool the previous state of versioning
297295
*/
298-
public function enableVersioning($enable = true)
296+
public function enableVersioning(bool $enable = true)
299297
{
300298
$wasEnabled = $this->versioningIsEnabled;
301-
$this->versioningIsEnabled = (bool) $enable;
299+
$this->versioningIsEnabled = $enable;
302300
$this->namespaceVersion = '';
303301
$this->ids = [];
304302

src/Symfony/Component/Cache/Traits/MemcachedTrait.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ private function init(\Memcached $client, string $namespace, int $defaultLifetim
8484
*
8585
* @throws \ErrorException When invalid options or servers are provided
8686
*/
87-
public static function createConnection($servers, array $options = [])
87+
public static function createConnection(string | array $servers, array $options = [])
8888
{
8989
if (\is_string($servers)) {
9090
$servers = [$servers];
91-
} elseif (!\is_array($servers)) {
92-
throw new InvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, "%s" given.', \gettype($servers)));
9391
}
9492
if (!static::isSupported()) {
9593
throw new CacheException('Memcached >= 2.2.0 is required.');

src/Symfony/Component/Cache/Traits/RedisTrait.php

+3-11
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,14 @@ trait RedisTrait
4747
private $redis;
4848
private $marshaller;
4949

50-
/**
51-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
52-
*/
53-
private function init($redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
50+
private function init(\Redis | \RedisArray | \RedisCluster | \Predis\ClientInterface | RedisProxy | RedisClusterProxy $redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
5451
{
5552
parent::__construct($namespace, $defaultLifetime);
5653

5754
if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
5855
throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
5956
}
6057

61-
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
62-
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redisClient)));
63-
}
64-
6558
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getOptions()->exceptions) {
6659
$options = clone $redisClient->getOptions();
6760
\Closure::bind(function () { $this->options['exceptions'] = false; }, $options, $options)();
@@ -82,14 +75,13 @@ private function init($redisClient, string $namespace, int $defaultLifetime, ?Ma
8275
* - redis:///var/run/redis.sock
8376
* - redis://secret@/var/run/redis.sock/13
8477
*
85-
* @param string $dsn
86-
* @param array $options See self::$defaultConnectionOptions
78+
* @param array $options See self::$defaultConnectionOptions
8779
*
8880
* @throws InvalidArgumentException when the DSN is invalid
8981
*
9082
* @return \Redis|\RedisCluster|RedisClusterProxy|RedisProxy|\Predis\ClientInterface According to the "class" option
9183
*/
92-
public static function createConnection($dsn, array $options = [])
84+
public static function createConnection(string $dsn, array $options = [])
9385
{
9486
if (0 === strpos($dsn, 'redis:')) {
9587
$scheme = 'redis';

src/Symfony/Component/Config/Definition/BaseNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ public function getInfo()
156156

157157
/**
158158
* Sets the example configuration for this node.
159-
*
160-
* @param string|array $example
161159
*/
162-
public function setExample($example)
160+
public function setExample(string | array $example)
163161
{
164162
$this->setAttribute('example', $example);
165163
}

src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ public function info(string $info)
6969
/**
7070
* Sets example configuration.
7171
*
72-
* @param string|array $example
73-
*
7472
* @return $this
7573
*/
76-
public function example($example)
74+
public function example(string | array $example)
7775
{
7876
return $this->attribute('example', $example);
7977
}

src/Symfony/Component/Console/Command/Command.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public function mergeApplicationDefinition(bool $mergeArgs = true)
364364
*
365365
* @return $this
366366
*/
367-
public function setDefinition($definition)
367+
public function setDefinition(array | InputDefinition $definition)
368368
{
369369
if ($definition instanceof InputDefinition) {
370370
$this->definition = $definition;

src/Symfony/Component/Console/Command/LazyCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function mergeApplicationDefinition(bool $mergeArgs = true): void
9090
/**
9191
* @return $this
9292
*/
93-
public function setDefinition($definition): self
93+
public function setDefinition(array | InputDefinition $definition): self
9494
{
9595
$this->getCommand()->setDefinition($definition);
9696

0 commit comments

Comments
 (0)