Merge branch '5.4' into 6.3

* 5.4:
  Fix implicitly-required parameters
  List CS fix in .git-blame-ignore-revs
  Apply php-cs-fixer fix --rules nullable_type_declaration_for_default_null_value
  [Messenger][AmazonSqs] Allow async-aws/sqs version 2
This commit is contained in:
Nicolas Grekas
2024-01-23 15:32:00 +01:00
79 changed files with 222 additions and 104 deletions

View File

@@ -81,7 +81,7 @@ class Button implements \IteratorAggregate, FormInterface
throw new BadMethodCallException('Buttons cannot have children.');
}
public function setParent(FormInterface $parent = null): static
public function setParent(?FormInterface $parent = null): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
@@ -107,7 +107,7 @@ class Button implements \IteratorAggregate, FormInterface
*
* @throws BadMethodCallException
*/
public function add(string|FormInterface $child, string $type = null, array $options = []): static
public function add(string|FormInterface $child, ?string $type = null, array $options = []): static
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@@ -338,7 +338,7 @@ class Button implements \IteratorAggregate, FormInterface
return null === $this->parent;
}
public function createView(FormView $parent = null): FormView
public function createView(?FormView $parent = null): FormView
{
if (null === $parent && $this->parent) {
$parent = $this->parent->createView();

View File

@@ -56,7 +56,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* @throws BadMethodCallException
*/
public function add(string|FormBuilderInterface $child, string $type = null, array $options = []): static
public function add(string|FormBuilderInterface $child, ?string $type = null, array $options = []): static
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@@ -68,7 +68,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* @throws BadMethodCallException
*/
public function create(string $name, string $type = null, array $options = []): FormBuilderInterface
public function create(string $name, ?string $type = null, array $options = []): FormBuilderInterface
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@@ -220,7 +220,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* @throws BadMethodCallException
*/
public function setDataMapper(DataMapperInterface $dataMapper = null): static
public function setDataMapper(?DataMapperInterface $dataMapper = null): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);

View File

@@ -57,7 +57,7 @@ class ArrayChoiceList implements ChoiceListInterface
* incrementing integers are used as
* values
*/
public function __construct(iterable $choices, callable $value = null)
public function __construct(iterable $choices, ?callable $value = null)
{
if ($choices instanceof \Traversable) {
$choices = iterator_to_array($choices);

View File

@@ -26,17 +26,17 @@ use Symfony\Component\Form\FormTypeInterface;
*/
final class ChoiceLoader extends AbstractStaticOption implements ChoiceLoaderInterface
{
public function loadChoiceList(callable $value = null): ChoiceListInterface
public function loadChoiceList(?callable $value = null): ChoiceListInterface
{
return $this->getOption()->loadChoiceList($value);
}
public function loadChoicesForValues(array $values, callable $value = null): array
public function loadChoicesForValues(array $values, ?callable $value = null): array
{
return $this->getOption()->loadChoicesForValues($values, $value);
}
public function loadValuesForChoices(array $choices, callable $value = null): array
public function loadValuesForChoices(array $choices, ?callable $value = null): array
{
return $this->getOption()->loadValuesForChoices($choices, $value);
}

View File

@@ -33,7 +33,7 @@ interface ChoiceListFactoryInterface
*
* @param callable|null $filter The callable filtering the choices
*/
public function createListFromChoices(iterable $choices, callable $value = null, callable $filter = null): ChoiceListInterface;
public function createListFromChoices(iterable $choices, ?callable $value = null, ?callable $filter = null): ChoiceListInterface;
/**
* Creates a choice list that is loaded with the given loader.
@@ -44,7 +44,7 @@ interface ChoiceListFactoryInterface
*
* @param callable|null $filter The callable filtering the choices
*/
public function createListFromLoader(ChoiceLoaderInterface $loader, callable $value = null, callable $filter = null): ChoiceListInterface;
public function createListFromLoader(ChoiceLoaderInterface $loader, ?callable $value = null, ?callable $filter = null): ChoiceListInterface;
/**
* Creates a view for the given choice list.
@@ -78,5 +78,5 @@ interface ChoiceListFactoryInterface
* @param array|callable|null $attr The callable generating the HTML attributes
* @param array|callable $labelTranslationParameters The parameters used to translate the choice labels
*/
public function createView(ChoiceListInterface $list, array|callable $preferredChoices = null, callable|false $label = null, callable $index = null, callable $groupBy = null, array|callable $attr = null, array|callable $labelTranslationParameters = []): ChoiceListView;
public function createView(ChoiceListInterface $list, array|callable|null $preferredChoices = null, callable|false|null $label = null, ?callable $index = null, ?callable $groupBy = null, array|callable|null $attr = null, array|callable $labelTranslationParameters = []): ChoiceListView;
}

View File

@@ -30,7 +30,7 @@ use Symfony\Contracts\Translation\TranslatableInterface;
*/
class DefaultChoiceListFactory implements ChoiceListFactoryInterface
{
public function createListFromChoices(iterable $choices, callable $value = null, callable $filter = null): ChoiceListInterface
public function createListFromChoices(iterable $choices, ?callable $value = null, ?callable $filter = null): ChoiceListInterface
{
if ($filter) {
// filter the choice list lazily
@@ -43,7 +43,7 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
return new ArrayChoiceList($choices, $value);
}
public function createListFromLoader(ChoiceLoaderInterface $loader, callable $value = null, callable $filter = null): ChoiceListInterface
public function createListFromLoader(ChoiceLoaderInterface $loader, ?callable $value = null, ?callable $filter = null): ChoiceListInterface
{
if ($filter) {
$loader = new FilterChoiceLoaderDecorator($loader, $filter);
@@ -52,7 +52,7 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
return new LazyChoiceList($loader, $value);
}
public function createView(ChoiceListInterface $list, array|callable $preferredChoices = null, callable|false $label = null, callable $index = null, callable $groupBy = null, array|callable $attr = null, array|callable $labelTranslationParameters = []): ChoiceListView
public function createView(ChoiceListInterface $list, array|callable|null $preferredChoices = null, callable|false|null $label = null, ?callable $index = null, ?callable $groupBy = null, array|callable|null $attr = null, array|callable $labelTranslationParameters = []): ChoiceListView
{
$preferredViews = [];
$preferredViewsOrder = [];

View File

@@ -41,7 +41,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
private ChoiceListFactoryInterface $decoratedFactory;
private PropertyAccessorInterface $propertyAccessor;
public function __construct(ChoiceListFactoryInterface $decoratedFactory, PropertyAccessorInterface $propertyAccessor = null)
public function __construct(ChoiceListFactoryInterface $decoratedFactory, ?PropertyAccessorInterface $propertyAccessor = null)
{
$this->decoratedFactory = $decoratedFactory;
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();

View File

@@ -45,7 +45,7 @@ class LazyChoiceList implements ChoiceListInterface
*
* @param callable|null $value The callable generating the choice values
*/
public function __construct(ChoiceLoaderInterface $loader, callable $value = null)
public function __construct(ChoiceLoaderInterface $loader, ?callable $value = null)
{
$this->loader = $loader;
$this->value = null === $value ? null : $value(...);

View File

@@ -24,12 +24,12 @@ abstract class AbstractChoiceLoader implements ChoiceLoaderInterface
/**
* @final
*/
public function loadChoiceList(callable $value = null): ChoiceListInterface
public function loadChoiceList(?callable $value = null): ChoiceListInterface
{
return new ArrayChoiceList($this->choices ??= $this->loadChoices(), $value);
}
public function loadChoicesForValues(array $values, callable $value = null): array
public function loadChoicesForValues(array $values, ?callable $value = null): array
{
if (!$values) {
return [];
@@ -38,7 +38,7 @@ abstract class AbstractChoiceLoader implements ChoiceLoaderInterface
return $this->doLoadChoicesForValues($values, $value);
}
public function loadValuesForChoices(array $choices, callable $value = null): array
public function loadValuesForChoices(array $choices, ?callable $value = null): array
{
if (!$choices) {
return [];

View File

@@ -34,7 +34,7 @@ interface ChoiceLoaderInterface
* @param callable|null $value The callable which generates the values
* from choices
*/
public function loadChoiceList(callable $value = null): ChoiceListInterface;
public function loadChoiceList(?callable $value = null): ChoiceListInterface;
/**
* Loads the choices corresponding to the given values.
@@ -50,7 +50,7 @@ interface ChoiceLoaderInterface
* values in this array are ignored
* @param callable|null $value The callable generating the choice values
*/
public function loadChoicesForValues(array $values, callable $value = null): array;
public function loadChoicesForValues(array $values, ?callable $value = null): array;
/**
* Loads the values corresponding to the given choices.
@@ -68,5 +68,5 @@ interface ChoiceLoaderInterface
*
* @return string[]
*/
public function loadValuesForChoices(array $choices, callable $value = null): array;
public function loadValuesForChoices(array $choices, ?callable $value = null): array;
}

View File

@@ -52,12 +52,12 @@ class FilterChoiceLoaderDecorator extends AbstractChoiceLoader
return $choices ?? [];
}
public function loadChoicesForValues(array $values, callable $value = null): array
public function loadChoicesForValues(array $values, ?callable $value = null): array
{
return array_filter($this->decoratedLoader->loadChoicesForValues($values, $value), $this->filter);
}
public function loadValuesForChoices(array $choices, callable $value = null): array
public function loadValuesForChoices(array $choices, ?callable $value = null): array
{
return $this->decoratedLoader->loadValuesForChoices(array_filter($choices, $this->filter), $value);
}

View File

@@ -19,12 +19,12 @@ namespace Symfony\Component\Form\ChoiceList\Loader;
*/
class IntlCallbackChoiceLoader extends CallbackChoiceLoader
{
public function loadChoicesForValues(array $values, callable $value = null): array
public function loadChoicesForValues(array $values, ?callable $value = null): array
{
return parent::loadChoicesForValues(array_filter($values), $value);
}
public function loadValuesForChoices(array $choices, callable $value = null): array
public function loadValuesForChoices(array $choices, ?callable $value = null): array
{
$choices = array_filter($choices);

View File

@@ -42,7 +42,7 @@ class DebugCommand extends Command
private array $guessers;
private ?FileLinkFormatter $fileLinkFormatter;
public function __construct(FormRegistryInterface $formRegistry, array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [], array $extensions = [], array $guessers = [], FileLinkFormatter $fileLinkFormatter = null)
public function __construct(FormRegistryInterface $formRegistry, array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [], array $extensions = [], array $guessers = [], ?FileLinkFormatter $fileLinkFormatter = null)
{
parent::__construct();

View File

@@ -26,7 +26,7 @@ class TextDescriptor extends Descriptor
{
private ?FileLinkFormatter $fileLinkFormatter;
public function __construct(FileLinkFormatter $fileLinkFormatter = null)
public function __construct(?FileLinkFormatter $fileLinkFormatter = null)
{
$this->fileLinkFormatter = $fileLinkFormatter;
}
@@ -190,7 +190,7 @@ class TextDescriptor extends Descriptor
return $options;
}
private function formatClassLink(string $class, string $text = null): string
private function formatClassLink(string $class, ?string $text = null): string
{
$text ??= $class;

View File

@@ -23,7 +23,7 @@ use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
*/
class DescriptorHelper extends BaseDescriptorHelper
{
public function __construct(FileLinkFormatter $fileLinkFormatter = null)
public function __construct(?FileLinkFormatter $fileLinkFormatter = null)
{
$this
->register('txt', new TextDescriptor($fileLinkFormatter))

View File

@@ -21,7 +21,7 @@ class TransformationFailedException extends RuntimeException
private ?string $invalidMessage;
private array $invalidMessageParameters;
public function __construct(string $message = '', int $code = 0, \Throwable $previous = null, string $invalidMessage = null, array $invalidMessageParameters = [])
public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null, ?string $invalidMessage = null, array $invalidMessageParameters = [])
{
parent::__construct($message, $code, $previous);
@@ -34,7 +34,7 @@ class TransformationFailedException extends RuntimeException
* @param string|null $invalidMessage The message or message key
* @param array $invalidMessageParameters Data to be passed into the translator
*/
public function setInvalidMessage(string $invalidMessage = null, array $invalidMessageParameters = []): void
public function setInvalidMessage(?string $invalidMessage = null, array $invalidMessageParameters = []): void
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);

View File

@@ -32,7 +32,7 @@ class CoreExtension extends AbstractExtension
private ChoiceListFactoryInterface $choiceListFactory;
private ?TranslatorInterface $translator;
public function __construct(PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null, TranslatorInterface $translator = null)
public function __construct(?PropertyAccessorInterface $propertyAccessor = null, ?ChoiceListFactoryInterface $choiceListFactory = null, ?TranslatorInterface $translator = null)
{
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
$this->choiceListFactory = $choiceListFactory ?? new CachingFactoryDecorator(new PropertyAccessDecorator(new DefaultChoiceListFactory(), $this->propertyAccessor));

View File

@@ -31,7 +31,7 @@ class PropertyPathAccessor implements DataAccessorInterface
{
private PropertyAccessorInterface $propertyAccessor;
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
public function __construct(?PropertyAccessorInterface $propertyAccessor = null)
{
$this->propertyAccessor = $propertyAccessor ?? PropertyAccess::createPropertyAccessor();
}

View File

@@ -27,7 +27,7 @@ class DataMapper implements DataMapperInterface
{
private DataAccessorInterface $dataAccessor;
public function __construct(DataAccessorInterface $dataAccessor = null)
public function __construct(?DataAccessorInterface $dataAccessor = null)
{
$this->dataAccessor = $dataAccessor ?? new ChainAccessor([
new CallbackAccessor(),

View File

@@ -0,0 +1,118 @@
<?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\Form\Extension\Core\DataMapper;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\PropertyAccess\Exception\AccessException;
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
trigger_deprecation('symfony/form', '5.2', 'The "%s" class is deprecated. Use "%s" instead.', PropertyPathMapper::class, DataMapper::class);
/**
* Maps arrays/objects to/from forms using property paths.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since symfony/form 5.2. Use {@see DataMapper} instead.
*/
class PropertyPathMapper implements DataMapperInterface
{
private $propertyAccessor;
public function __construct(?PropertyAccessorInterface $propertyAccessor = null)
{
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
}
/**
* {@inheritdoc}
*/
public function mapDataToForms($data, iterable $forms)
{
$empty = null === $data || [] === $data;
if (!$empty && !\is_array($data) && !\is_object($data)) {
throw new UnexpectedTypeException($data, 'object, array or empty');
}
foreach ($forms as $form) {
$propertyPath = $form->getPropertyPath();
$config = $form->getConfig();
if (!$empty && null !== $propertyPath && $config->getMapped()) {
$form->setData($this->getPropertyValue($data, $propertyPath));
} else {
$form->setData($config->getData());
}
}
}
/**
* {@inheritdoc}
*/
public function mapFormsToData(iterable $forms, &$data)
{
if (null === $data) {
return;
}
if (!\is_array($data) && !\is_object($data)) {
throw new UnexpectedTypeException($data, 'object, array or empty');
}
foreach ($forms as $form) {
$propertyPath = $form->getPropertyPath();
$config = $form->getConfig();
// Write-back is disabled if the form is not synchronized (transformation failed),
// if the form was not submitted and if the form is disabled (modification not allowed)
if (null !== $propertyPath && $config->getMapped() && $form->isSubmitted() && $form->isSynchronized() && !$form->isDisabled()) {
$propertyValue = $form->getData();
// If the field is of type DateTimeInterface and the data is the same skip the update to
// keep the original object hash
if ($propertyValue instanceof \DateTimeInterface && $propertyValue == $this->getPropertyValue($data, $propertyPath)) {
continue;
}
// If the data is identical to the value in $data, we are
// dealing with a reference
if (!\is_object($data) || !$config->getByReference() || $propertyValue !== $this->getPropertyValue($data, $propertyPath)) {
$this->propertyAccessor->setValue($data, $propertyPath, $propertyValue);
}
}
}
}
private function getPropertyValue($data, $propertyPath)
{
try {
return $this->propertyAccessor->getValue($data, $propertyPath);
} catch (AccessException $e) {
if (\is_array($data) && $e instanceof NoSuchIndexException) {
return null;
}
if (!$e instanceof UninitializedPropertyException
// For versions without UninitializedPropertyException check the exception message
&& (class_exists(UninitializedPropertyException::class) || !str_contains($e->getMessage(), 'You should initialize it'))
) {
throw $e;
}
return null;
}
}
}

View File

@@ -39,7 +39,7 @@ abstract class BaseDateTimeTransformer implements DataTransformerInterface
*
* @throws InvalidArgumentException if a timezone is not valid
*/
public function __construct(string $inputTimezone = null, string $outputTimezone = null)
public function __construct(?string $inputTimezone = null, ?string $outputTimezone = null)
{
$this->inputTimezone = $inputTimezone ?: date_default_timezone_get();
$this->outputTimezone = $outputTimezone ?: date_default_timezone_get();

View File

@@ -48,7 +48,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
* @param string[]|null $fields The date fields
* @param bool $pad Whether to use padding
*/
public function __construct(array $fields = null, bool $pad = false)
public function __construct(?array $fields = null, bool $pad = false)
{
$this->fields = $fields ?? ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'invert'];
$this->pad = $pad;

View File

@@ -33,7 +33,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
* @param string[]|null $fields The date fields
* @param bool $pad Whether to use padding
*/
public function __construct(string $inputTimezone = null, string $outputTimezone = null, array $fields = null, bool $pad = false, \DateTimeInterface $referenceDate = null)
public function __construct(?string $inputTimezone = null, ?string $outputTimezone = null, ?array $fields = null, bool $pad = false, ?\DateTimeInterface $referenceDate = null)
{
parent::__construct($inputTimezone, $outputTimezone);

View File

@@ -25,7 +25,7 @@ class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer
public const HTML5_FORMAT = 'Y-m-d\\TH:i:s';
public const HTML5_FORMAT_NO_SECONDS = 'Y-m-d\\TH:i';
public function __construct(string $inputTimezone = null, string $outputTimezone = null, private bool $withSeconds = false)
public function __construct(?string $inputTimezone = null, ?string $outputTimezone = null, private bool $withSeconds = false)
{
parent::__construct($inputTimezone, $outputTimezone);
}

View File

@@ -41,7 +41,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
*
* @throws UnexpectedTypeException If a format is not supported or if a timezone is not a string
*/
public function __construct(string $inputTimezone = null, string $outputTimezone = null, int $dateFormat = null, int $timeFormat = null, int $calendar = \IntlDateFormatter::GREGORIAN, string $pattern = null)
public function __construct(?string $inputTimezone = null, ?string $outputTimezone = null, ?int $dateFormat = null, ?int $timeFormat = null, int $calendar = \IntlDateFormatter::GREGORIAN, ?string $pattern = null)
{
parent::__construct($inputTimezone, $outputTimezone);

View File

@@ -47,7 +47,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
* @param string $format The date format
* @param string|null $parseFormat The parse format when different from $format
*/
public function __construct(string $inputTimezone = null, string $outputTimezone = null, string $format = 'Y-m-d H:i:s', string $parseFormat = null)
public function __construct(?string $inputTimezone = null, ?string $outputTimezone = null, string $format = 'Y-m-d H:i:s', ?string $parseFormat = null)
{
parent::__construct($inputTimezone, $outputTimezone);

View File

@@ -28,7 +28,7 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
* @param int|null $roundingMode One of the ROUND_ constants in this class
* @param string|null $locale locale used for transforming
*/
public function __construct(?bool $grouping = false, ?int $roundingMode = \NumberFormatter::ROUND_DOWN, string $locale = null)
public function __construct(?bool $grouping = false, ?int $roundingMode = \NumberFormatter::ROUND_DOWN, ?string $locale = null)
{
parent::__construct(0, $grouping, $roundingMode, $locale);
}

View File

@@ -23,7 +23,7 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
{
private int $divisor;
public function __construct(?int $scale = 2, ?bool $grouping = true, ?int $roundingMode = \NumberFormatter::ROUND_HALFUP, ?int $divisor = 1, string $locale = null)
public function __construct(?int $scale = 2, ?bool $grouping = true, ?int $roundingMode = \NumberFormatter::ROUND_HALFUP, ?int $divisor = 1, ?string $locale = null)
{
parent::__construct($scale ?? 2, $grouping ?? true, $roundingMode, $locale);

View File

@@ -32,7 +32,7 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
private ?int $scale;
private ?string $locale;
public function __construct(int $scale = null, ?bool $grouping = false, ?int $roundingMode = \NumberFormatter::ROUND_HALFUP, string $locale = null)
public function __construct(?int $scale = null, ?bool $grouping = false, ?int $roundingMode = \NumberFormatter::ROUND_HALFUP, ?string $locale = null)
{
$this->scale = $scale;
$this->grouping = $grouping ?? false;

View File

@@ -46,7 +46,7 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
*
* @throws UnexpectedTypeException if the given value of type is unknown
*/
public function __construct(int $scale = null, string $type = null, int $roundingMode = \NumberFormatter::ROUND_HALFUP, bool $html5Format = false)
public function __construct(?int $scale = null, ?string $type = null, int $roundingMode = \NumberFormatter::ROUND_HALFUP, bool $html5Format = false)
{
$type ??= self::FRACTIONAL;

View File

@@ -21,7 +21,7 @@ class StringToFloatTransformer implements DataTransformerInterface
{
private ?int $scale;
public function __construct(int $scale = null)
public function __construct(?int $scale = null)
{
$this->scale = $scale;
}

View File

@@ -32,7 +32,7 @@ class ResizeFormListener implements EventSubscriberInterface
private \Closure|bool $deleteEmpty;
public function __construct(string $type, array $options = [], bool $allowAdd = false, bool $allowDelete = false, bool|callable $deleteEmpty = false, array $prototypeOptions = null)
public function __construct(string $type, array $options = [], bool $allowAdd = false, bool $allowDelete = false, bool|callable $deleteEmpty = false, ?array $prototypeOptions = null)
{
$this->type = $type;
$this->allowAdd = $allowAdd;

View File

@@ -24,7 +24,7 @@ class TransformationFailureListener implements EventSubscriberInterface
{
private ?TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator = null)
public function __construct(?TranslatorInterface $translator = null)
{
$this->translator = $translator;
}

View File

@@ -52,7 +52,7 @@ class ChoiceType extends AbstractType
private ChoiceListFactoryInterface $choiceListFactory;
private ?TranslatorInterface $translator;
public function __construct(ChoiceListFactoryInterface $choiceListFactory = null, TranslatorInterface $translator = null)
public function __construct(?ChoiceListFactoryInterface $choiceListFactory = null, ?TranslatorInterface $translator = null)
{
$this->choiceListFactory = $choiceListFactory ?? new CachingFactoryDecorator(
new PropertyAccessDecorator(

View File

@@ -28,7 +28,7 @@ class ColorType extends AbstractType
private ?TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator = null)
public function __construct(?TranslatorInterface $translator = null)
{
$this->translator = $translator;
}

View File

@@ -36,7 +36,7 @@ class FileType extends AbstractType
private ?TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator = null)
public function __construct(?TranslatorInterface $translator = null)
{
$this->translator = $translator;
}

View File

@@ -30,7 +30,7 @@ class FormType extends BaseType
{
private DataMapper $dataMapper;
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
public function __construct(?PropertyAccessorInterface $propertyAccessor = null)
{
$this->dataMapper = new DataMapper(new ChainAccessor([
new CallbackAccessor(),

View File

@@ -112,7 +112,7 @@ class TimezoneType extends AbstractType
return $timezones;
}
private static function getIntlTimezones(string $input, string $locale = null): array
private static function getIntlTimezones(string $input, ?string $locale = null): array
{
$timezones = array_flip(Timezones::getNames($locale));

View File

@@ -23,7 +23,7 @@ class TransformationFailureExtension extends AbstractTypeExtension
{
private ?TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator = null)
public function __construct(?TranslatorInterface $translator = null)
{
$this->translator = $translator;
}

View File

@@ -26,7 +26,7 @@ class CsrfExtension extends AbstractExtension
private ?TranslatorInterface $translator;
private ?string $translationDomain;
public function __construct(CsrfTokenManagerInterface $tokenManager, TranslatorInterface $translator = null, string $translationDomain = null)
public function __construct(CsrfTokenManagerInterface $tokenManager, ?TranslatorInterface $translator = null, ?string $translationDomain = null)
{
$this->tokenManager = $tokenManager;
$this->translator = $translator;

View File

@@ -40,7 +40,7 @@ class CsrfValidationListener implements EventSubscriberInterface
];
}
public function __construct(string $fieldName, CsrfTokenManagerInterface $tokenManager, string $tokenId, string $errorMessage, TranslatorInterface $translator = null, string $translationDomain = null, ServerParams $serverParams = null)
public function __construct(string $fieldName, CsrfTokenManagerInterface $tokenManager, string $tokenId, string $errorMessage, ?TranslatorInterface $translator = null, ?string $translationDomain = null, ?ServerParams $serverParams = null)
{
$this->fieldName = $fieldName;
$this->tokenManager = $tokenManager;

View File

@@ -35,7 +35,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
private ?string $translationDomain;
private ?ServerParams $serverParams;
public function __construct(CsrfTokenManagerInterface $defaultTokenManager, bool $defaultEnabled = true, string $defaultFieldName = '_token', TranslatorInterface $translator = null, string $translationDomain = null, ServerParams $serverParams = null)
public function __construct(CsrfTokenManagerInterface $defaultTokenManager, bool $defaultEnabled = true, string $defaultFieldName = '_token', ?TranslatorInterface $translator = null, ?string $translationDomain = null, ?ServerParams $serverParams = null)
{
$this->defaultTokenManager = $defaultTokenManager;
$this->defaultEnabled = $defaultEnabled;

View File

@@ -76,7 +76,7 @@ class FormDataCollector extends DataCollector implements FormDataCollectorInterf
/**
* Does nothing. The data is collected during the form event listeners.
*/
public function collect(Request $request, Response $response, \Throwable $exception = null): void
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
}
@@ -259,7 +259,7 @@ class FormDataCollector extends DataCollector implements FormDataCollectorInterf
return $output;
}
private function &recursiveBuildFinalFormTree(FormInterface $form = null, FormView $view, array &$outputByHash)
private function &recursiveBuildFinalFormTree(?FormInterface $form = null, FormView $view, array &$outputByHash)
{
$viewHash = spl_object_hash($view);
$formHash = null;

View File

@@ -66,7 +66,7 @@ class ResolvedTypeDataCollectorProxy implements ResolvedFormTypeInterface
return $builder;
}
public function createView(FormInterface $form, FormView $parent = null): FormView
public function createView(FormInterface $form, ?FormView $parent = null): FormView
{
return $this->proxiedType->createView($form, $parent);
}

View File

@@ -33,7 +33,7 @@ class ResolvedTypeFactoryDataCollectorProxy implements ResolvedFormTypeFactoryIn
$this->dataCollector = $dataCollector;
}
public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ResolvedFormTypeInterface $parent = null): ResolvedFormTypeInterface
public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ?ResolvedFormTypeInterface $parent = null): ResolvedFormTypeInterface
{
return new ResolvedTypeDataCollectorProxy(
$this->proxiedFactory->createResolvedType($type, $typeExtensions, $parent),

View File

@@ -31,7 +31,7 @@ class HttpFoundationRequestHandler implements RequestHandlerInterface
{
private ServerParams $serverParams;
public function __construct(ServerParams $serverParams = null)
public function __construct(?ServerParams $serverParams = null)
{
$this->serverParams = $serverParams ?? new ServerParams();
}

View File

@@ -24,7 +24,7 @@ class FormTypeHttpFoundationExtension extends AbstractTypeExtension
{
private RequestHandlerInterface $requestHandler;
public function __construct(RequestHandlerInterface $requestHandler = null)
public function __construct(?RequestHandlerInterface $requestHandler = null)
{
$this->requestHandler = $requestHandler ?? new HttpFoundationRequestHandler();
}

View File

@@ -31,7 +31,7 @@ class FormTypeValidatorExtension extends BaseValidatorExtension
private ViolationMapper $violationMapper;
private bool $legacyErrorMessages;
public function __construct(ValidatorInterface $validator, bool $legacyErrorMessages = true, FormRendererInterface $formRenderer = null, TranslatorInterface $translator = null)
public function __construct(ValidatorInterface $validator, bool $legacyErrorMessages = true, ?FormRendererInterface $formRenderer = null, ?TranslatorInterface $translator = null)
{
$this->validator = $validator;
$this->violationMapper = new ViolationMapper($formRenderer, $translator);

View File

@@ -26,7 +26,7 @@ class UploadValidatorExtension extends AbstractTypeExtension
private TranslatorInterface $translator;
private ?string $translationDomain;
public function __construct(TranslatorInterface $translator, string $translationDomain = null)
public function __construct(TranslatorInterface $translator, ?string $translationDomain = null)
{
$this->translator = $translator;
$this->translationDomain = $translationDomain;

View File

@@ -32,7 +32,7 @@ class ValidatorExtension extends AbstractExtension
private ?TranslatorInterface $translator;
private bool $legacyErrorMessages;
public function __construct(ValidatorInterface $validator, bool $legacyErrorMessages = true, FormRendererInterface $formRenderer = null, TranslatorInterface $translator = null)
public function __construct(ValidatorInterface $validator, bool $legacyErrorMessages = true, ?FormRendererInterface $formRenderer = null, ?TranslatorInterface $translator = null)
{
$this->legacyErrorMessages = $legacyErrorMessages;

View File

@@ -32,7 +32,7 @@ class ViolationMapper implements ViolationMapperInterface
private ?TranslatorInterface $translator;
private bool $allowNonSynchronized = false;
public function __construct(FormRendererInterface $formRenderer = null, TranslatorInterface $translator = null)
public function __construct(?FormRendererInterface $formRenderer = null, ?TranslatorInterface $translator = null)
{
$this->formRenderer = $formRenderer;
$this->translator = $translator;

View File

@@ -218,7 +218,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
return true;
}
public function setParent(FormInterface $parent = null): static
public function setParent(?FormInterface $parent = null): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
@@ -720,7 +720,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
return iterator_to_array($this->children);
}
public function add(FormInterface|string $child, string $type = null, array $options = []): static
public function add(FormInterface|string $child, ?string $type = null, array $options = []): static
{
if ($this->submitted) {
throw new AlreadySubmittedException('You cannot add children to a submitted form.');
@@ -883,7 +883,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
return \count($this->children);
}
public function createView(FormView $parent = null): FormView
public function createView(?FormView $parent = null): FormView
{
if (null === $parent && $this->parent) {
$parent = $this->parent->createView();

View File

@@ -45,7 +45,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
$this->setFormFactory($factory);
}
public function add(FormBuilderInterface|string $child, string $type = null, array $options = []): static
public function add(FormBuilderInterface|string $child, ?string $type = null, array $options = []): static
{
if ($this->locked) {
throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
@@ -71,7 +71,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
return $this;
}
public function create(string $name, string $type = null, array $options = []): FormBuilderInterface
public function create(string $name, ?string $type = null, array $options = []): FormBuilderInterface
{
if ($this->locked) {
throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');

View File

@@ -27,7 +27,7 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
*
* @param array<string, mixed> $options
*/
public function add(string|FormBuilderInterface $child, string $type = null, array $options = []): static;
public function add(string|FormBuilderInterface $child, ?string $type = null, array $options = []): static;
/**
* Creates a form builder.
@@ -36,7 +36,7 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
* @param string|null $type The type of the form or null if name is a property
* @param array<string, mixed> $options
*/
public function create(string $name, string $type = null, array $options = []): self;
public function create(string $name, ?string $type = null, array $options = []): self;
/**
* Returns a child by name.

View File

@@ -347,7 +347,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* @return $this
*/
public function setDataMapper(DataMapperInterface $dataMapper = null): static
public function setDataMapper(?DataMapperInterface $dataMapper = null): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);

View File

@@ -45,7 +45,7 @@ class FormError
*
* @see \Symfony\Component\Translation\Translator
*/
public function __construct(string $message, string $messageTemplate = null, array $messageParameters = [], int $messagePluralization = null, mixed $cause = null)
public function __construct(string $message, ?string $messageTemplate = null, array $messageParameters = [], ?int $messagePluralization = null, mixed $cause = null)
{
$this->message = $message;
$this->messageTemplate = $messageTemplate ?: $message;

View File

@@ -54,7 +54,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
* @throws Exception\LogicException when trying to add a child to a non-compound form
* @throws Exception\UnexpectedTypeException if $child or $type has an unexpected type
*/
public function add(self|string $child, string $type = null, array $options = []): static;
public function add(self|string $child, ?string $type = null, array $options = []): static;
/**
* Returns the child with the given name.
@@ -285,5 +285,5 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
*/
public function isRoot(): bool;
public function createView(FormView $parent = null): FormView;
public function createView(?FormView $parent = null): FormView;
}

View File

@@ -31,7 +31,7 @@ class FormRenderer implements FormRendererInterface
private array $hierarchyLevelMap = [];
private array $variableStack = [];
public function __construct(FormRendererEngineInterface $engine, CsrfTokenManagerInterface $csrfTokenManager = null)
public function __construct(FormRendererEngineInterface $engine, ?CsrfTokenManagerInterface $csrfTokenManager = null)
{
$this->engine = $engine;
$this->csrfTokenManager = $csrfTokenManager;

View File

@@ -52,7 +52,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
private bool $methodRendered = false;
public function __construct(self $parent = null)
public function __construct(?self $parent = null)
{
$this->parent = $parent;
}

View File

@@ -35,7 +35,7 @@ class NativeRequestHandler implements RequestHandlerInterface
'type',
];
public function __construct(ServerParams $params = null)
public function __construct(?ServerParams $params = null)
{
$this->serverParams = $params ?? new ServerParams();
}

View File

@@ -30,7 +30,7 @@ class PreloadedExtension implements FormExtensionInterface
* @param FormTypeInterface[] $types The types that the extension should support
* @param FormTypeExtensionInterface[][] $typeExtensions The type extensions that the extension should support
*/
public function __construct(array $types, array $typeExtensions, FormTypeGuesserInterface $typeGuesser = null)
public function __construct(array $types, array $typeExtensions, ?FormTypeGuesserInterface $typeGuesser = null)
{
$this->typeExtensions = $typeExtensions;
$this->typeGuesser = $typeGuesser;

View File

@@ -37,7 +37,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
/**
* @param FormTypeExtensionInterface[] $typeExtensions
*/
public function __construct(FormTypeInterface $innerType, array $typeExtensions = [], ResolvedFormTypeInterface $parent = null)
public function __construct(FormTypeInterface $innerType, array $typeExtensions = [], ?ResolvedFormTypeInterface $parent = null)
{
foreach ($typeExtensions as $extension) {
if (!$extension instanceof FormTypeExtensionInterface) {
@@ -87,7 +87,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
return $builder;
}
public function createView(FormInterface $form, FormView $parent = null): FormView
public function createView(FormInterface $form, ?FormView $parent = null): FormView
{
return $this->newView($parent);
}
@@ -177,7 +177,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
*
* Override this method if you want to customize the view class.
*/
protected function newView(FormView $parent = null): FormView
protected function newView(?FormView $parent = null): FormView
{
return new FormView($parent);
}

View File

@@ -16,7 +16,7 @@ namespace Symfony\Component\Form;
*/
class ResolvedFormTypeFactory implements ResolvedFormTypeFactoryInterface
{
public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ResolvedFormTypeInterface $parent = null): ResolvedFormTypeInterface
public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ?ResolvedFormTypeInterface $parent = null): ResolvedFormTypeInterface
{
return new ResolvedFormType($type, $typeExtensions, $parent);
}

View File

@@ -30,5 +30,5 @@ interface ResolvedFormTypeFactoryInterface
* @throws Exception\UnexpectedTypeException if the types parent {@link FormTypeInterface::getParent()} is not a string
* @throws Exception\InvalidArgumentException if the types parent cannot be retrieved from any extension
*/
public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ResolvedFormTypeInterface $parent = null): ResolvedFormTypeInterface;
public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ?ResolvedFormTypeInterface $parent = null): ResolvedFormTypeInterface;
}

View File

@@ -52,7 +52,7 @@ interface ResolvedFormTypeInterface
/**
* Creates a new form view for a form of this type.
*/
public function createView(FormInterface $form, FormView $parent = null): FormView;
public function createView(FormInterface $form, ?FormView $parent = null): FormView;
/**
* Configures a form builder for the type hierarchy.

View File

@@ -741,7 +741,7 @@ class DefaultChoiceListFactoryTest extends TestCase
public function testPassTranslatableInterfaceAsLabelDoesntCastItToString()
{
$message = new class() implements TranslatableInterface {
public function trans(TranslatorInterface $translator, string $locale = null): string
public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
return 'my_message';
}

View File

@@ -1125,7 +1125,7 @@ class CompoundFormTest extends TestCase
return $builder->getForm();
}
private function getBuilder(string $name = 'name', string $dataClass = null, array $options = []): FormBuilder
private function getBuilder(string $name = 'name', ?string $dataClass = null, array $options = []): FormBuilder
{
return new FormBuilder($name, $dataClass, new EventDispatcher(), $this->factory, $options);
}

View File

@@ -31,5 +31,5 @@ abstract class BaseDateTimeTransformerTestCase extends TestCase
$this->createDateTimeTransformer(null, 'that_timezone_does_not_exist');
}
abstract protected function createDateTimeTransformer(string $inputTimezone = null, string $outputTimezone = null): BaseDateTimeTransformer;
abstract protected function createDateTimeTransformer(?string $inputTimezone = null, ?string $outputTimezone = null): BaseDateTimeTransformer;
}

View File

@@ -536,7 +536,7 @@ class DateTimeToArrayTransformerTest extends BaseDateTimeTransformerTestCase
]);
}
protected function createDateTimeTransformer(string $inputTimezone = null, string $outputTimezone = null): BaseDateTimeTransformer
protected function createDateTimeTransformer(?string $inputTimezone = null, ?string $outputTimezone = null): BaseDateTimeTransformer
{
return new DateTimeToArrayTransformer($inputTimezone, $outputTimezone);
}

View File

@@ -120,7 +120,7 @@ class DateTimeToHtml5LocalDateTimeTransformerTest extends BaseDateTimeTransforme
$transformer->reverseTransform('2010-2010-2010');
}
protected function createDateTimeTransformer(string $inputTimezone = null, string $outputTimezone = null): BaseDateTimeTransformer
protected function createDateTimeTransformer(?string $inputTimezone = null, ?string $outputTimezone = null): BaseDateTimeTransformer
{
return new DateTimeToHtml5LocalDateTimeTransformer($inputTimezone, $outputTimezone);
}

View File

@@ -373,7 +373,7 @@ class DateTimeToLocalizedStringTransformerTest extends BaseDateTimeTransformerTe
$transformer->reverseTransform('12345');
}
protected function createDateTimeTransformer(string $inputTimezone = null, string $outputTimezone = null): BaseDateTimeTransformer
protected function createDateTimeTransformer(?string $inputTimezone = null, ?string $outputTimezone = null): BaseDateTimeTransformer
{
return new DateTimeToLocalizedStringTransformer($inputTimezone, $outputTimezone);
}

View File

@@ -138,7 +138,7 @@ class DateTimeToRfc3339TransformerTest extends BaseDateTimeTransformerTestCase
];
}
protected function createDateTimeTransformer(string $inputTimezone = null, string $outputTimezone = null): BaseDateTimeTransformer
protected function createDateTimeTransformer(?string $inputTimezone = null, ?string $outputTimezone = null): BaseDateTimeTransformer
{
return new DateTimeToRfc3339Transformer($inputTimezone, $outputTimezone);
}

View File

@@ -171,7 +171,7 @@ class DateTimeToStringTransformerTest extends BaseDateTimeTransformerTestCase
$reverseTransformer->reverseTransform('2010-04-31');
}
protected function createDateTimeTransformer(string $inputTimezone = null, string $outputTimezone = null): BaseDateTimeTransformer
protected function createDateTimeTransformer(?string $inputTimezone = null, ?string $outputTimezone = null): BaseDateTimeTransformer
{
return new DateTimeToStringTransformer($inputTimezone, $outputTimezone);
}

View File

@@ -115,7 +115,7 @@ class DateTimeToTimestampTransformerTest extends BaseDateTimeTransformerTestCase
$reverseTransformer->reverseTransform('2010-2010-2010');
}
protected function createDateTimeTransformer(string $inputTimezone = null, string $outputTimezone = null): BaseDateTimeTransformer
protected function createDateTimeTransformer(?string $inputTimezone = null, ?string $outputTimezone = null): BaseDateTimeTransformer
{
return new DateTimeToTimestampTransformer($inputTimezone, $outputTimezone);
}

View File

@@ -71,7 +71,7 @@ class StringToFloatTransformerTest extends TestCase
/**
* @dataProvider provideReverseTransformations
*/
public function testReverseTransform($from, $to, int $scale = null)
public function testReverseTransform($from, $to, ?int $scale = null)
{
$transformer = new StringToFloatTransformer($scale);

View File

@@ -120,7 +120,7 @@ class CollectionTypeTest extends BaseTypeTestCase
$form = $this->factory->create(static::TESTED_TYPE, null, [
'entry_type' => AuthorType::class,
'allow_delete' => true,
'delete_empty' => fn (Author $obj = null) => null === $obj || empty($obj->firstName),
'delete_empty' => fn (?Author $obj = null) => null === $obj || empty($obj->firstName),
]);
$form->setData([new Author('Bob'), new Author('Alice')]);

View File

@@ -715,7 +715,7 @@ class FormValidatorTest extends ConstraintValidatorTestCase
return new FormValidator();
}
private function getBuilder(string $name = 'name', string $dataClass = null, array $options = []): FormBuilder
private function getBuilder(string $name = 'name', ?string $dataClass = null, array $options = []): FormBuilder
{
$options = array_replace([
'constraints' => [],

View File

@@ -1128,7 +1128,7 @@ class SimpleFormTest extends TestCase
return $this->getBuilder()->getForm();
}
private function getBuilder(?string $name = 'name', string $dataClass = null, array $options = []): FormBuilder
private function getBuilder(?string $name = 'name', ?string $dataClass = null, array $options = []): FormBuilder
{
return new FormBuilder($name, $dataClass, new EventDispatcher(), new FormFactory(new FormRegistry([], new ResolvedFormTypeFactory())), $options);
}

View File

@@ -20,7 +20,7 @@ class ServerParams
{
private ?RequestStack $requestStack;
public function __construct(RequestStack $requestStack = null)
public function __construct(?RequestStack $requestStack = null)
{
$this->requestStack = $requestStack;
}