Skip to content

Commit ebfff03

Browse files
Add union types
1 parent dd2b162 commit ebfff03

15 files changed

+23
-46
lines changed

AppVariable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function getDebug()
152152
*
153153
* @return array
154154
*/
155-
public function getFlashes($types = null)
155+
public function getFlashes(string|array|null $types = null)
156156
{
157157
try {
158158
if (null === $session = $this->getSession()) {

Command/DebugCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ private function getLoaderPaths(string $name = null): array
293293
return $loaderPaths;
294294
}
295295

296-
private function getMetadata(string $type, $entity)
296+
private function getMetadata(string $type, mixed $entity)
297297
{
298298
if ('globals' === $type) {
299299
return $entity;
@@ -351,7 +351,7 @@ private function getMetadata(string $type, $entity)
351351
return null;
352352
}
353353

354-
private function getPrettyMetadata(string $type, $entity, bool $decorated): ?string
354+
private function getPrettyMetadata(string $type, mixed $entity, bool $decorated): ?string
355355
{
356356
if ('tests' === $type) {
357357
return '';

ErrorRenderer/TwigErrorRenderer.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ class TwigErrorRenderer implements ErrorRendererInterface
3232
/**
3333
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
3434
*/
35-
public function __construct(Environment $twig, HtmlErrorRenderer $fallbackErrorRenderer = null, $debug = false)
35+
public function __construct(Environment $twig, HtmlErrorRenderer $fallbackErrorRenderer = null, bool|callable $debug = false)
3636
{
37-
if (!\is_bool($debug) && !\is_callable($debug)) {
38-
throw new \TypeError(sprintf('Argument 3 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, get_debug_type($debug)));
39-
}
40-
4137
$this->twig = $twig;
4238
$this->fallbackErrorRenderer = $fallbackErrorRenderer ?? new HtmlErrorRenderer();
4339
$this->debug = $debug;

Extension/CodeExtension.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ final class CodeExtension extends AbstractExtension
2626
private $charset;
2727
private $projectDir;
2828

29-
/**
30-
* @param string|FileLinkFormatter $fileLinkFormat The format for links to source files
31-
*/
32-
public function __construct($fileLinkFormat, string $projectDir, string $charset)
29+
public function __construct(string|FileLinkFormatter $fileLinkFormat, string $projectDir, string $charset)
3330
{
3431
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3532
$this->projectDir = str_replace('\\', '/', $projectDir).'/';

Extension/FormExtension.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function getFieldChoices(FormView $view): iterable
158158
yield from $this->createFieldChoicesList($view->vars['choices'], $view->vars['choice_translation_domain']);
159159
}
160160

161-
private function createFieldChoicesList(iterable $choices, $translationDomain): iterable
161+
private function createFieldChoicesList(iterable $choices, string|false|null $translationDomain): iterable
162162
{
163163
foreach ($choices as $choice) {
164164
$translatableLabel = $this->createFieldTranslation($choice->label, [], $translationDomain);
@@ -174,7 +174,7 @@ private function createFieldChoicesList(iterable $choices, $translationDomain):
174174
}
175175
}
176176

177-
private function createFieldTranslation(?string $value, array $parameters, $domain): ?string
177+
private function createFieldTranslation(?string $value, array $parameters, string|false|null $domain): ?string
178178
{
179179
if (!$this->translator || !$value || false === $domain) {
180180
return $value;
@@ -189,11 +189,9 @@ private function createFieldTranslation(?string $value, array $parameters, $doma
189189
*
190190
* This is a function and not callable due to performance reasons.
191191
*
192-
* @param string|array $selectedValue The selected value to compare
193-
*
194192
* @see ChoiceView::isSelected()
195193
*/
196-
function twig_is_selected_choice(ChoiceView $choice, $selectedValue): bool
194+
function twig_is_selected_choice(ChoiceView $choice, string|array $selectedValue): bool
197195
{
198196
if (\is_array($selectedValue)) {
199197
return \in_array($choice->value, $selectedValue, true);

Extension/HttpKernelRuntime.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ public function __construct(FragmentHandler $handler, FragmentUriGeneratorInterf
3434
/**
3535
* Renders a fragment.
3636
*
37-
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
38-
*
3937
* @see FragmentHandler::render()
4038
*/
41-
public function renderFragment($uri, array $options = []): string
39+
public function renderFragment(string|ControllerReference $uri, array $options = []): string
4240
{
4341
$strategy = $options['strategy'] ?? 'inline';
4442
unset($options['strategy']);
@@ -49,11 +47,9 @@ public function renderFragment($uri, array $options = []): string
4947
/**
5048
* Renders a fragment.
5149
*
52-
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
53-
*
5450
* @see FragmentHandler::render()
5551
*/
56-
public function renderFragmentStrategy(string $strategy, $uri, array $options = []): string
52+
public function renderFragmentStrategy(string $strategy, string|ControllerReference $uri, array $options = []): string
5753
{
5854
return $this->handler->render($uri, $strategy, $options);
5955
}

Extension/SecurityExtension.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ public function __construct(AuthorizationCheckerInterface $securityChecker = nul
3535
$this->impersonateUrlGenerator = $impersonateUrlGenerator;
3636
}
3737

38-
/**
39-
* @param mixed $object
40-
*/
41-
public function isGranted($role, $object = null, string $field = null): bool
38+
public function isGranted(mixed $role, mixed $object = null, string $field = null): bool
4239
{
4340
if (null === $this->securityChecker) {
4441
return false;

Extension/SerializerRuntime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(SerializerInterface $serializer)
2626
$this->serializer = $serializer;
2727
}
2828

29-
public function serialize($data, string $format = 'json', array $context = []): string
29+
public function serialize(mixed $data, string $format = 'json', array $context = []): string
3030
{
3131
return $this->serializer->serialize($data, $format, $context);
3232
}

Extension/TranslationExtension.php

Lines changed: 2 additions & 3 deletions
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)) {

Extension/WorkflowExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function getMarkedPlaces(object $subject, bool $placesNameOnly = true, st
102102
* Use a string (the place name) to get place metadata
103103
* Use a Transition instance to get transition metadata
104104
*/
105-
public function getMetadata(object $subject, string $key, $metadataSubject = null, string $name = null)
105+
public function getMetadata(object $subject, string $key, string|Transition|null $metadataSubject = null, string $name = null)
106106
{
107107
return $this
108108
->workflowRegistry

0 commit comments

Comments
 (0)