This commit is contained in:
Nicolas Grekas
2025-07-10 09:12:18 +02:00
parent 45ee2b63c3
commit 7a4bc0e606
75 changed files with 175 additions and 176 deletions

View File

@@ -50,7 +50,7 @@ abstract class AbstractExtension implements FormExtensionInterface
}
if (!isset($this->types[$name])) {
throw new InvalidArgumentException(sprintf('The type "%s" cannot be loaded by this extension.', $name));
throw new InvalidArgumentException(\sprintf('The type "%s" cannot be loaded by this extension.', $name));
}
return $this->types[$name];

View File

@@ -315,7 +315,7 @@ class Button implements \IteratorAggregate, FormInterface
*
* @return $this
*
* @throws Exception\AlreadySubmittedException if the button has already been submitted
* @throws AlreadySubmittedException if the button has already been submitted
*/
public function submit(array|string|null $submittedData, bool $clearMissing = true): static
{

View File

@@ -65,7 +65,7 @@ class DebugCommand extends Command
new InputArgument('class', InputArgument::OPTIONAL, 'The form type class'),
new InputArgument('option', InputArgument::OPTIONAL, 'The form type option'),
new InputOption('show-deprecated', null, InputOption::VALUE_NONE, 'Display deprecated options in form types'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, \sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
])
->setHelp(<<<'EOF'
The <info>%command.name%</info> command displays information about form types.
@@ -126,7 +126,7 @@ EOF
$object = $resolvedType->getOptionsResolver();
if (!$object->isDefined($option)) {
$message = sprintf('Option "%s" is not defined in "%s".', $option, $resolvedType->getInnerType()::class);
$message = \sprintf('Option "%s" is not defined in "%s".', $option, $resolvedType->getInnerType()::class);
if ($alternatives = $this->findAlternatives($option, $object->getDefinedOptions())) {
if (1 === \count($alternatives)) {
@@ -160,7 +160,7 @@ EOF
$classes = $this->getFqcnTypeClasses($shortClassName);
if (0 === $count = \count($classes)) {
$message = sprintf("Could not find type \"%s\" into the following namespaces:\n %s", $shortClassName, implode("\n ", $this->namespaces));
$message = \sprintf("Could not find type \"%s\" into the following namespaces:\n %s", $shortClassName, implode("\n ", $this->namespaces));
$allTypes = array_merge($this->getCoreTypes(), $this->types);
if ($alternatives = $this->findAlternatives($shortClassName, $allTypes)) {
@@ -178,10 +178,10 @@ EOF
return $classes[0];
}
if (!$input->isInteractive()) {
throw new InvalidArgumentException(sprintf("The type \"%s\" is ambiguous.\n\nDid you mean one of these?\n %s.", $shortClassName, implode("\n ", $classes)));
throw new InvalidArgumentException(\sprintf("The type \"%s\" is ambiguous.\n\nDid you mean one of these?\n %s.", $shortClassName, implode("\n ", $classes)));
}
return $io->choice(sprintf("The type \"%s\" is ambiguous.\n\nSelect one of the following form types to display its information:", $shortClassName), $classes, $classes[0]);
return $io->choice(\sprintf("The type \"%s\" is ambiguous.\n\nSelect one of the following form types to display its information:", $shortClassName), $classes, $classes[0]);
}
private function getFqcnTypeClasses(string $shortClassName): array

View File

@@ -46,7 +46,7 @@ abstract class Descriptor implements DescriptorInterface
null === $object => $this->describeDefaults($options),
$object instanceof ResolvedFormTypeInterface => $this->describeResolvedFormType($object, $options),
$object instanceof OptionsResolver => $this->describeOption($object, $options),
default => throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_debug_type($object))),
default => throw new \InvalidArgumentException(\sprintf('Object of type "%s" is not describable.', get_debug_type($object))),
};
}

View File

@@ -83,7 +83,7 @@ class TextDescriptor extends Descriptor
'extension' => 'Extension options',
], $formOptions);
$this->output->title(sprintf('%s (Block prefix: "%s")', $resolvedFormType->getInnerType()::class, $resolvedFormType->getInnerType()->getBlockPrefix()));
$this->output->title(\sprintf('%s (Block prefix: "%s")', $resolvedFormType->getInnerType()::class, $resolvedFormType->getInnerType()->getBlockPrefix()));
if ($formOptions) {
$this->output->table($tableHeaders, $this->buildTableRows($tableHeaders, $formOptions));
@@ -134,7 +134,7 @@ class TextDescriptor extends Descriptor
}
array_pop($rows);
$this->output->title(sprintf('%s (%s)', $options['type']::class, $options['option']));
$this->output->title(\sprintf('%s (%s)', $options['type']::class, $options['option']));
$this->output->table([], $rows);
}
@@ -175,7 +175,7 @@ class TextDescriptor extends Descriptor
} else {
$options[$group][] = null;
}
$options[$group][] = sprintf('<info>%s</info>', (new \ReflectionClass($class))->getShortName());
$options[$group][] = \sprintf('<info>%s</info>', (new \ReflectionClass($class))->getShortName());
$options[$group][] = new TableSeparator();
sort($opt);
@@ -199,7 +199,7 @@ class TextDescriptor extends Descriptor
return $text;
}
return sprintf('<href=%s>%s</>', $fileLink, $text);
return \sprintf('<href=%s>%s</>', $fileLink, $text);
}
private function getFileLink(string $class): string

View File

@@ -92,7 +92,7 @@ class FormPass implements CompilerPassInterface
}
if (!$extendsTypes) {
throw new InvalidArgumentException(sprintf('The getExtendedTypes() method for service "%s" does not return any extended types.', $serviceId));
throw new InvalidArgumentException(\sprintf('The getExtendedTypes() method for service "%s" does not return any extended types.', $serviceId));
}
}
}

View File

@@ -15,6 +15,6 @@ class UnexpectedTypeException extends InvalidArgumentException
{
public function __construct(mixed $value, string $expectedType)
{
parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, get_debug_type($value)));
parent::__construct(\sprintf('Expected argument of type "%s", "%s" given', $expectedType, get_debug_type($value)));
}
}

View File

@@ -74,7 +74,7 @@ class ArrayToPartsTransformer implements DataTransformerInterface
return null;
}
throw new TransformationFailedException(sprintf('The keys "%s" should not be empty.', implode('", "', $emptyKeys)));
throw new TransformationFailedException(\sprintf('The keys "%s" should not be empty.', implode('", "', $emptyKeys)));
}
return $result;

View File

@@ -48,13 +48,13 @@ abstract class BaseDateTimeTransformer implements DataTransformerInterface
try {
new \DateTimeZone($this->inputTimezone);
} catch (\Exception $e) {
throw new InvalidArgumentException(sprintf('Input timezone is invalid: "%s".', $this->inputTimezone), $e->getCode(), $e);
throw new InvalidArgumentException(\sprintf('Input timezone is invalid: "%s".', $this->inputTimezone), $e->getCode(), $e);
}
try {
new \DateTimeZone($this->outputTimezone);
} catch (\Exception $e) {
throw new InvalidArgumentException(sprintf('Output timezone is invalid: "%s".', $this->outputTimezone), $e->getCode(), $e);
throw new InvalidArgumentException(\sprintf('Output timezone is invalid: "%s".', $this->outputTimezone), $e->getCode(), $e);
}
}
}

View File

@@ -47,7 +47,7 @@ class ChoiceToValueTransformer implements DataTransformerInterface
return null;
}
throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique.', $value));
throw new TransformationFailedException(\sprintf('The choice "%s" does not exist or is not unique.', $value));
}
return current($choices);

View File

@@ -124,19 +124,19 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
}
}
if (\count($emptyFields) > 0) {
throw new TransformationFailedException(sprintf('The fields "%s" should not be empty.', implode('", "', $emptyFields)));
throw new TransformationFailedException(\sprintf('The fields "%s" should not be empty.', implode('", "', $emptyFields)));
}
if (isset($value['invert']) && !\is_bool($value['invert'])) {
throw new TransformationFailedException('The value of "invert" must be boolean.');
}
foreach (self::AVAILABLE_FIELDS as $field => $char) {
if ('invert' !== $field && isset($value[$field]) && !ctype_digit((string) $value[$field])) {
throw new TransformationFailedException(sprintf('This amount of "%s" is invalid.', $field));
throw new TransformationFailedException(\sprintf('This amount of "%s" is invalid.', $field));
}
}
try {
if (!empty($value['weeks'])) {
$interval = sprintf(
$interval = \sprintf(
'P%sY%sM%sWT%sH%sM%sS',
empty($value['years']) ? '0' : $value['years'],
empty($value['months']) ? '0' : $value['months'],
@@ -146,7 +146,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
empty($value['seconds']) ? '0' : $value['seconds']
);
} else {
$interval = sprintf(
$interval = \sprintf(
'P%sY%sM%sDT%sH%sM%sS',
empty($value['years']) ? '0' : $value['years'],
empty($value['months']) ? '0' : $value['months'],

View File

@@ -81,7 +81,7 @@ class DateIntervalToStringTransformer implements DataTransformerInterface
}
$valuePattern = '/^'.preg_replace('/%([yYmMdDhHiIsSwW])(\w)/', '(?P<$1>\d+)$2', $this->format).'$/';
if (!preg_match($valuePattern, $value)) {
throw new TransformationFailedException(sprintf('Value "%s" contains intervals not accepted by format "%s".', $value, $this->format));
throw new TransformationFailedException(\sprintf('Value "%s" contains intervals not accepted by format "%s".', $value, $this->format));
}
try {
$dateInterval = new \DateInterval($value);

View File

@@ -123,7 +123,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
}
if (\count($emptyFields) > 0) {
throw new TransformationFailedException(sprintf('The fields "%s" should not be empty.', implode('", "', $emptyFields)));
throw new TransformationFailedException(\sprintf('The fields "%s" should not be empty.', implode('", "', $emptyFields)));
}
if (isset($value['month']) && !ctype_digit((string) $value['month'])) {
@@ -155,7 +155,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
}
try {
$dateTime = new \DateTime(sprintf(
$dateTime = new \DateTime(\sprintf(
'%s-%s-%s %s:%s:%s',
empty($value['year']) ? $this->referenceDate->format('Y') : $value['year'],
empty($value['month']) ? $this->referenceDate->format('m') : $value['month'],

View File

@@ -85,7 +85,7 @@ class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer
// to maintain backwards compatibility we do not strictly validate the submitted date
// see https://github.com/symfony/symfony/issues/28699
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?/', $dateTimeLocal, $matches)) {
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $dateTimeLocal));
throw new TransformationFailedException(\sprintf('The date "%s" is not a valid date.', $dateTimeLocal));
}
try {
@@ -99,7 +99,7 @@ class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer
}
if (!checkdate($matches[2], $matches[3], $matches[1])) {
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
throw new TransformationFailedException(\sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
}
return $dateTime;

View File

@@ -126,7 +126,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
} elseif (false === $timestamp) {
// the value couldn't be parsed but the Intl extension didn't report an error code, this
// could be the case when the Intl polyfill is used which always returns 0 as the error code
throw new TransformationFailedException(sprintf('"%s" could not be parsed as a date.', $value));
throw new TransformationFailedException(\sprintf('"%s" could not be parsed as a date.', $value));
}
try {
@@ -135,7 +135,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
$dateTime = new \DateTime(gmdate('Y-m-d', $timestamp), new \DateTimeZone($this->outputTimezone));
} else {
// read timestamp into DateTime object - the formatter delivers a timestamp
$dateTime = new \DateTime(sprintf('@%s', $timestamp));
$dateTime = new \DateTime(\sprintf('@%s', $timestamp));
}
// set timezone separately, as it would be ignored if set via the constructor,
// see https://php.net/datetime.construct

View File

@@ -64,7 +64,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
}
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})T\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))$/', $rfc3339, $matches)) {
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $rfc3339));
throw new TransformationFailedException(\sprintf('The date "%s" is not a valid date.', $rfc3339));
}
try {
@@ -78,7 +78,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
}
if (!checkdate($matches[2], $matches[3], $matches[1])) {
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
throw new TransformationFailedException(\sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
}
return $dateTime;

View File

@@ -38,7 +38,7 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
$decimalSeparator = $this->getNumberFormatter()->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
if (\is_string($value) && str_contains($value, $decimalSeparator)) {
throw new TransformationFailedException(sprintf('The value "%s" is not a valid integer.', $value));
throw new TransformationFailedException(\sprintf('The value "%s" is not a valid integer.', $value));
}
$result = parent::reverseTransform($value);

View File

@@ -72,7 +72,7 @@ class IntlTimeZoneToStringTransformer implements DataTransformerInterface
$intlTimeZone = \IntlTimeZone::createTimeZone($value);
if ('Etc/Unknown' === $intlTimeZone->getID()) {
throw new TransformationFailedException(sprintf('Unknown timezone identifier "%s".', $value));
throw new TransformationFailedException(\sprintf('Unknown timezone identifier "%s".', $value));
}
return $intlTimeZone;

View File

@@ -147,7 +147,7 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
$remainder = trim($remainder, " \t\n\r\0\x0b\xc2\xa0");
if ('' !== $remainder) {
throw new TransformationFailedException(sprintf('The number contains unrecognized characters: "%s".', $remainder));
throw new TransformationFailedException(\sprintf('The number contains unrecognized characters: "%s".', $remainder));
}
}

View File

@@ -162,7 +162,7 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
$remainder = trim($remainder, " \t\n\r\0\x0b\xc2\xa0");
if ('' !== $remainder) {
throw new TransformationFailedException(sprintf('The number contains unrecognized characters: "%s".', $remainder));
throw new TransformationFailedException(\sprintf('The number contains unrecognized characters: "%s".', $remainder));
}
}

View File

@@ -65,7 +65,7 @@ class UlidToStringTransformer implements DataTransformerInterface
try {
$ulid = new Ulid($value);
} catch (\InvalidArgumentException $e) {
throw new TransformationFailedException(sprintf('The value "%s" is not a valid ULID.', $value), $e->getCode(), $e);
throw new TransformationFailedException(\sprintf('The value "%s" is not a valid ULID.', $value), $e->getCode(), $e);
}
return $ulid;

View File

@@ -63,13 +63,13 @@ class UuidToStringTransformer implements DataTransformerInterface
}
if (!Uuid::isValid($value)) {
throw new TransformationFailedException(sprintf('The value "%s" is not a valid UUID.', $value));
throw new TransformationFailedException(\sprintf('The value "%s" is not a valid UUID.', $value));
}
try {
return Uuid::fromString($value);
} catch (\InvalidArgumentException $e) {
throw new TransformationFailedException(sprintf('The value "%s" is not a valid UUID.', $value), $e->getCode(), $e);
throw new TransformationFailedException(\sprintf('The value "%s" is not a valid UUID.', $value), $e->getCode(), $e);
}
}
}

View File

@@ -73,7 +73,7 @@ class ValueToDuplicatesTransformer implements DataTransformerInterface
return null;
}
throw new TransformationFailedException(sprintf('The keys "%s" should not be empty.', implode('", "', $emptyKeys)));
throw new TransformationFailedException(\sprintf('The keys "%s" should not be empty.', implode('", "', $emptyKeys)));
}
return $result;

View File

@@ -40,7 +40,7 @@ class WeekToArrayTransformer implements DataTransformerInterface
}
if (!\is_string($value)) {
throw new TransformationFailedException(sprintf('Value is expected to be a string but was "%s".', get_debug_type($value)));
throw new TransformationFailedException(\sprintf('Value is expected to be a string but was "%s".', get_debug_type($value)));
}
if (0 === preg_match('/^(?P<year>\d{4})-W(?P<week>\d{2})$/', $value, $matches)) {
@@ -70,7 +70,7 @@ class WeekToArrayTransformer implements DataTransformerInterface
}
if (!\is_array($value)) {
throw new TransformationFailedException(sprintf('Value is expected to be an array, but was "%s".', get_debug_type($value)));
throw new TransformationFailedException(\sprintf('Value is expected to be an array, but was "%s".', get_debug_type($value)));
}
if (!\array_key_exists('year', $value)) {
@@ -82,7 +82,7 @@ class WeekToArrayTransformer implements DataTransformerInterface
}
if ($additionalKeys = array_diff(array_keys($value), ['year', 'week'])) {
throw new TransformationFailedException(sprintf('Expected only keys "year" and "week" to be present, but also got ["%s"].', implode('", "', $additionalKeys)));
throw new TransformationFailedException(\sprintf('Expected only keys "year" and "week" to be present, but also got ["%s"].', implode('", "', $additionalKeys)));
}
if (null === $value['year'] && null === $value['week']) {
@@ -90,18 +90,18 @@ class WeekToArrayTransformer implements DataTransformerInterface
}
if (!\is_int($value['year'])) {
throw new TransformationFailedException(sprintf('Year is expected to be an integer, but was "%s".', get_debug_type($value['year'])));
throw new TransformationFailedException(\sprintf('Year is expected to be an integer, but was "%s".', get_debug_type($value['year'])));
}
if (!\is_int($value['week'])) {
throw new TransformationFailedException(sprintf('Week is expected to be an integer, but was "%s".', get_debug_type($value['week'])));
throw new TransformationFailedException(\sprintf('Week is expected to be an integer, but was "%s".', get_debug_type($value['week'])));
}
// The 28th December is always in the last week of the year
if (date('W', strtotime('28th December '.$value['year'])) < $value['week']) {
throw new TransformationFailedException(sprintf('Week "%d" does not exist for year "%d".', $value['week'], $value['year']));
throw new TransformationFailedException(\sprintf('Week "%d" does not exist for year "%d".', $value['week'], $value['year']));
}
return sprintf('%d-W%02d', $value['year'], $value['week']);
return \sprintf('%d-W%02d', $value['year'], $value['week']);
}
}

View File

@@ -52,9 +52,9 @@ abstract class BaseType extends AbstractType
if ($view->parent) {
if ('' !== ($parentFullName = $view->parent->vars['full_name'])) {
$id = sprintf('%s_%s', $view->parent->vars['id'], $name);
$fullName = sprintf('%s[%s]', $parentFullName, $name);
$uniqueBlockPrefix = sprintf('%s_%s', $view->parent->vars['unique_block_prefix'], $blockName);
$id = \sprintf('%s_%s', $view->parent->vars['id'], $name);
$fullName = \sprintf('%s[%s]', $parentFullName, $name);
$uniqueBlockPrefix = \sprintf('%s_%s', $view->parent->vars['unique_block_prefix'], $blockName);
} else {
$id = $name;
$fullName = $name;

View File

@@ -161,7 +161,7 @@ class ChoiceType extends AbstractType
// Throw exception if unknown values were submitted (multiple choices will be handled in a different event listener below)
if (\count($unknownValues) > 0 && !$options['multiple']) {
throw new TransformationFailedException(sprintf('The choices "%s" do not exist in the choice list.', implode('", "', array_keys($unknownValues))));
throw new TransformationFailedException(\sprintf('The choices "%s" do not exist in the choice list.', implode('", "', array_keys($unknownValues))));
}
$event->setData($knownValues);
@@ -185,7 +185,7 @@ class ChoiceType extends AbstractType
$message = strtr($messageTemplate, ['{{ value }}' => $clientDataAsString]);
}
$form->addError(new FormError($message, $messageTemplate, ['{{ value }}' => $clientDataAsString], null, new TransformationFailedException(sprintf('The choices "%s" do not exist in the choice list.', $clientDataAsString))));
$form->addError(new FormError($message, $messageTemplate, ['{{ value }}' => $clientDataAsString], null, new TransformationFailedException(\sprintf('The choices "%s" do not exist in the choice list.', $clientDataAsString))));
}
});

View File

@@ -30,7 +30,7 @@ class CountryType extends AbstractType
$resolver->setDefaults([
'choice_loader' => function (Options $options) {
if (!class_exists(Intl::class)) {
throw new LogicException(sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
throw new LogicException(\sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
}
$choiceTranslationLocale = $options['choice_translation_locale'];

View File

@@ -30,7 +30,7 @@ class CurrencyType extends AbstractType
$resolver->setDefaults([
'choice_loader' => function (Options $options) {
if (!class_exists(Intl::class)) {
throw new LogicException(sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
throw new LogicException(\sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
}
$choiceTranslationLocale = $options['choice_translation_locale'];

View File

@@ -206,7 +206,7 @@ class DateTimeType extends AbstractType
}
if ($date->getTimezone()->getName() !== $options['model_timezone']) {
trigger_deprecation('symfony/form', '6.4', sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is deprecated.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
trigger_deprecation('symfony/form', '6.4', \sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is deprecated.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
// throw new LogicException(sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is not supported.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
}
});
@@ -321,7 +321,7 @@ class DateTimeType extends AbstractType
$resolver->setNormalizer('date_format', static function (Options $options, $dateFormat) {
if (null !== $dateFormat && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
throw new LogicException(sprintf('Cannot use the "date_format" option of the "%s" with an HTML5 date.', self::class));
throw new LogicException(\sprintf('Cannot use the "date_format" option of the "%s" with an HTML5 date.', self::class));
}
return $dateFormat;
@@ -329,10 +329,10 @@ class DateTimeType extends AbstractType
$resolver->setNormalizer('widget', static function (Options $options, $widget) {
if ('single_text' === $widget) {
if (null !== $options['date_widget']) {
throw new LogicException(sprintf('Cannot use the "date_widget" option of the "%s" when the "widget" option is set to "single_text".', self::class));
throw new LogicException(\sprintf('Cannot use the "date_widget" option of the "%s" when the "widget" option is set to "single_text".', self::class));
}
if (null !== $options['time_widget']) {
throw new LogicException(sprintf('Cannot use the "time_widget" option of the "%s" when the "widget" option is set to "single_text".', self::class));
throw new LogicException(\sprintf('Cannot use the "time_widget" option of the "%s" when the "widget" option is set to "single_text".', self::class));
}
} elseif (null === $widget && null === $options['date_widget'] && null === $options['time_widget']) {
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option of form type "datetime" is deprecated. It will default to "single_text" in Symfony 7.0.');
@@ -343,7 +343,7 @@ class DateTimeType extends AbstractType
});
$resolver->setNormalizer('html5', static function (Options $options, $html5) {
if ($html5 && self::HTML5_FORMAT !== $options['format']) {
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
throw new LogicException(\sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
}
return $html5;

View File

@@ -61,7 +61,7 @@ class DateType extends AbstractType
if ('single_text' === $options['widget']) {
if ('' !== $pattern && !str_contains($pattern, 'y') && !str_contains($pattern, 'M') && !str_contains($pattern, 'd')) {
throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" or "d". Its current value is "%s".', $pattern));
throw new InvalidOptionsException(\sprintf('The "format" option should contain the letters "y", "M" or "d". Its current value is "%s".', $pattern));
}
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer(
@@ -74,7 +74,7 @@ class DateType extends AbstractType
));
} else {
if ('' !== $pattern && (!str_contains($pattern, 'y') || !str_contains($pattern, 'M') || !str_contains($pattern, 'd'))) {
throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern));
throw new InvalidOptionsException(\sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern));
}
$yearOptions = $monthOptions = $dayOptions = [
@@ -190,7 +190,7 @@ class DateType extends AbstractType
}
if ($date->getTimezone()->getName() !== $options['model_timezone']) {
trigger_deprecation('symfony/form', '6.4', sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is deprecated.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
trigger_deprecation('symfony/form', '6.4', \sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is deprecated.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
// throw new LogicException(sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is not supported.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
}
});
@@ -337,7 +337,7 @@ class DateType extends AbstractType
$resolver->setNormalizer('html5', static function (Options $options, $html5) {
if ($html5 && 'single_text' === $options['widget'] && self::HTML5_FORMAT !== $options['format']) {
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
throw new LogicException(\sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
}
return $html5;

View File

@@ -31,7 +31,7 @@ class LanguageType extends AbstractType
$resolver->setDefaults([
'choice_loader' => function (Options $options) {
if (!class_exists(Intl::class)) {
throw new LogicException(sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
throw new LogicException(\sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
}
$choiceTranslationLocale = $options['choice_translation_locale'];
$useAlpha3Codes = $options['alpha3'];

View File

@@ -30,7 +30,7 @@ class LocaleType extends AbstractType
$resolver->setDefaults([
'choice_loader' => function (Options $options) {
if (!class_exists(Intl::class)) {
throw new LogicException(sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
throw new LogicException(\sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
}
$choiceTranslationLocale = $options['choice_translation_locale'];

View File

@@ -48,7 +48,7 @@ class TimeType extends AbstractType
}
if (null !== $options['reference_date'] && $options['reference_date']->getTimezone()->getName() !== $options['model_timezone']) {
throw new InvalidConfigurationException(sprintf('The configured "model_timezone" (%s) must match the timezone of the "reference_date" (%s).', $options['model_timezone'], $options['reference_date']->getTimezone()->getName()));
throw new InvalidConfigurationException(\sprintf('The configured "model_timezone" (%s) must match the timezone of the "reference_date" (%s).', $options['model_timezone'], $options['reference_date']->getTimezone()->getName()));
}
if ($options['with_minutes']) {
@@ -69,9 +69,9 @@ class TimeType extends AbstractType
if ($options['with_seconds']) {
// handle seconds ignored by user's browser when with_seconds enabled
// https://codereview.chromium.org/450533009/
$e->setData(sprintf('%s:%s:%s', $matches['hours'], $matches['minutes'], $matches['seconds'] ?? '00'));
$e->setData(\sprintf('%s:%s:%s', $matches['hours'], $matches['minutes'], $matches['seconds'] ?? '00'));
} else {
$e->setData(sprintf('%s:%s', $matches['hours'], $matches['minutes']));
$e->setData(\sprintf('%s:%s', $matches['hours'], $matches['minutes']));
}
}
});
@@ -220,7 +220,7 @@ class TimeType extends AbstractType
}
if ($date->getTimezone()->getName() !== $options['model_timezone']) {
trigger_deprecation('symfony/form', '6.4', sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is deprecated.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
trigger_deprecation('symfony/form', '6.4', \sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is deprecated.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
// throw new LogicException(sprintf('Using a "%s" instance with a timezone ("%s") not matching the configured model timezone "%s" is not supported.', $date::class, $date->getTimezone()->getName(), $options['model_timezone']));
}
});

View File

@@ -49,7 +49,7 @@ class TimezoneType extends AbstractType
if ($options['intl']) {
if (!class_exists(Intl::class)) {
throw new LogicException(sprintf('The "symfony/intl" component is required to use "%s" with option "intl=true". Try running "composer require symfony/intl".', static::class));
throw new LogicException(\sprintf('The "symfony/intl" component is required to use "%s" with option "intl=true". Try running "composer require symfony/intl".', static::class));
}
$choiceTranslationLocale = $options['choice_translation_locale'];

View File

@@ -153,7 +153,7 @@ class WeekType extends AbstractType
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
$resolver->setNormalizer('html5', static function (Options $options, $html5) {
if ($html5 && 'single_text' !== $options['widget']) {
throw new LogicException(sprintf('The "widget" option of "%s" must be set to "single_text" when the "html5" option is enabled.', self::class));
throw new LogicException(\sprintf('The "widget" option of "%s" must be set to "single_text" when the "html5" option is enabled.', self::class));
}
return $html5;

View File

@@ -65,7 +65,7 @@ class FormDataCollector extends DataCollector implements FormDataCollectorInterf
public function __construct(FormDataExtractorInterface $dataExtractor)
{
if (!class_exists(ClassStub::class)) {
throw new \LogicException(sprintf('The VarDumper component is needed for using the "%s" class. Install symfony/var-dumper version 3.4 or above.', __CLASS__));
throw new \LogicException(\sprintf('The VarDumper component is needed for using the "%s" class. Install symfony/var-dumper version 3.4 or above.', __CLASS__));
}
$this->dataExtractor = $dataExtractor;

View File

@@ -40,7 +40,7 @@ class DependencyInjectionExtension implements FormExtensionInterface
public function getType(string $name): FormTypeInterface
{
if (!$this->typeContainer->has($name)) {
throw new InvalidArgumentException(sprintf('The field type "%s" is not registered in the service container.', $name));
throw new InvalidArgumentException(\sprintf('The field type "%s" is not registered in the service container.', $name));
}
return $this->typeContainer->get($name);
@@ -66,7 +66,7 @@ class DependencyInjectionExtension implements FormExtensionInterface
// validate the result of getExtendedTypes() to ensure it is consistent with the service definition
if (!\in_array($name, $extendedTypes, true)) {
throw new InvalidArgumentException(sprintf('The extended type "%s" specified for the type extension class "%s" does not match any of the actual extended types (["%s"]).', $name, $extension::class, implode('", "', $extendedTypes)));
throw new InvalidArgumentException(\sprintf('The extended type "%s" specified for the type extension class "%s" does not match any of the actual extended types (["%s"]).', $name, $extension::class, implode('", "', $extendedTypes)));
}
}
}

View File

@@ -101,7 +101,7 @@ class PasswordHasherListener
$parent = $this->getTargetForm($form)->getParent();
if (!($user = $parent?->getData()) || !$user instanceof PasswordAuthenticatedUserInterface) {
throw new InvalidConfigurationException(sprintf('The "hash_property_path" option only supports "%s" objects, "%s" given.', PasswordAuthenticatedUserInterface::class, get_debug_type($user)));
throw new InvalidConfigurationException(\sprintf('The "hash_property_path" option only supports "%s" objects, "%s" given.', PasswordAuthenticatedUserInterface::class, get_debug_type($user)));
}
return $user;

View File

@@ -95,7 +95,7 @@ class FormValidator extends ConstraintValidator
$fieldFormConstraint = new Form();
$fieldFormConstraint->groups = $group;
$this->context->setNode($this->context->getValue(), $field, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $field->getName()))->validate($field, $fieldFormConstraint, $group);
$validator->atPath(\sprintf('children[%s]', $field->getName()))->validate($field, $fieldFormConstraint, $group);
}
}
@@ -142,7 +142,7 @@ class FormValidator extends ConstraintValidator
if ($field->isSubmitted()) {
$this->resolvedGroups[$field] = $groups;
$this->context->setNode($this->context->getValue(), $field, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $field->getName()))->validate($field, $formConstraint);
$validator->atPath(\sprintf('children[%s]', $field->getName()))->validate($field, $formConstraint);
}
}
}
@@ -159,7 +159,7 @@ class FormValidator extends ConstraintValidator
if (!$child->isSynchronized()) {
$childrenSynchronized = false;
$this->context->setNode($this->context->getValue(), $child, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $child->getName()))->validate($child, $formConstraint);
$validator->atPath(\sprintf('children[%s]', $child->getName()))->validate($child, $formConstraint);
}
}

View File

@@ -232,7 +232,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
switch ($constraint::class) {
case Length::class:
if (is_numeric($constraint->min)) {
return new ValueGuess(sprintf('.{%s,}', (string) $constraint->min), Guess::LOW_CONFIDENCE);
return new ValueGuess(\sprintf('.{%s,}', (string) $constraint->min), Guess::LOW_CONFIDENCE);
}
break;
@@ -246,7 +246,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
case Range::class:
if (is_numeric($constraint->min)) {
return new ValueGuess(sprintf('.{%s,}', \strlen((string) $constraint->min)), Guess::LOW_CONFIDENCE);
return new ValueGuess(\sprintf('.{%s,}', \strlen((string) $constraint->min)), Guess::LOW_CONFIDENCE);
}
break;

View File

@@ -68,7 +68,7 @@ class MappingRule
foreach ($childNames as $childName) {
if (!$target->has($childName)) {
throw new ErrorMappingException(sprintf('The child "%s" of "%s" mapped by the rule "%s" in "%s" does not exist.', $childName, $target->getName(), $this->targetPath, $this->origin->getName()));
throw new ErrorMappingException(\sprintf('The child "%s" of "%s" mapped by the rule "%s" in "%s" does not exist.', $childName, $target->getName(), $this->targetPath, $this->origin->getName()));
}
$target = $target->get($childName);
}

View File

@@ -132,7 +132,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function getElement(int $index): string
{
if (!isset($this->elements[$index])) {
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the violation path.', $index));
}
return $this->elements[$index];
@@ -141,7 +141,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function isProperty(int $index): bool
{
if (!isset($this->isIndex[$index])) {
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the violation path.', $index));
}
return !$this->isIndex[$index];
@@ -150,7 +150,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function isIndex(int $index): bool
{
if (!isset($this->isIndex[$index])) {
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the violation path.', $index));
}
return $this->isIndex[$index];
@@ -176,7 +176,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function mapsForm(int $index): bool
{
if (!isset($this->mapsForm[$index])) {
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the violation path.', $index));
}
return $this->mapsForm[$index];

View File

@@ -619,7 +619,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
return null === $this->transformationFailure;
}
public function getTransformationFailure(): ?Exception\TransformationFailedException
public function getTransformationFailure(): ?TransformationFailedException
{
return $this->transformationFailure;
}
@@ -750,7 +750,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
$child = $this->config->getFormFactory()->createNamed($child, $type, null, $options);
}
} elseif ($child->getConfig()->getAutoInitialize()) {
throw new RuntimeException(sprintf('Automatic initialization is only supported on root forms. You should set the "auto_initialize" option to false on the field "%s".', $child->getName()));
throw new RuntimeException(\sprintf('Automatic initialization is only supported on root forms. You should set the "auto_initialize" option to false on the field "%s".', $child->getName()));
}
$this->children[$child->getName()] = $child;
@@ -812,7 +812,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
return $this->children[$name];
}
throw new OutOfBoundsException(sprintf('Child "%s" does not exist.', $name));
throw new OutOfBoundsException(\sprintf('Child "%s" does not exist.', $name));
}
/**
@@ -945,7 +945,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
$value = $transformer->transform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(sprintf('Unable to transform data for property path "%s": ', $this->getPropertyPath()).$exception->getMessage(), $exception->getCode(), $exception, $exception->getInvalidMessage(), $exception->getInvalidMessageParameters());
throw new TransformationFailedException(\sprintf('Unable to transform data for property path "%s": ', $this->getPropertyPath()).$exception->getMessage(), $exception->getCode(), $exception, $exception->getInvalidMessage(), $exception->getInvalidMessageParameters());
}
return $value;
@@ -965,7 +965,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
$value = $transformers[$i]->reverseTransform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(sprintf('Unable to reverse value for property path "%s": ', $this->getPropertyPath()).$exception->getMessage(), $exception->getCode(), $exception, $exception->getInvalidMessage(), $exception->getInvalidMessageParameters());
throw new TransformationFailedException(\sprintf('Unable to reverse value for property path "%s": ', $this->getPropertyPath()).$exception->getMessage(), $exception->getCode(), $exception, $exception->getInvalidMessage(), $exception->getInvalidMessageParameters());
}
return $value;
@@ -992,7 +992,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
$value = $transformer->transform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(sprintf('Unable to transform value for property path "%s": ', $this->getPropertyPath()).$exception->getMessage(), $exception->getCode(), $exception, $exception->getInvalidMessage(), $exception->getInvalidMessageParameters());
throw new TransformationFailedException(\sprintf('Unable to transform value for property path "%s": ', $this->getPropertyPath()).$exception->getMessage(), $exception->getCode(), $exception, $exception->getInvalidMessage(), $exception->getInvalidMessageParameters());
}
return $value;
@@ -1014,7 +1014,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
$value = $transformers[$i]->reverseTransform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(sprintf('Unable to reverse value for property path "%s": ', $this->getPropertyPath()).$exception->getMessage(), $exception->getCode(), $exception, $exception->getInvalidMessage(), $exception->getInvalidMessageParameters());
throw new TransformationFailedException(\sprintf('Unable to reverse value for property path "%s": ', $this->getPropertyPath()).$exception->getMessage(), $exception->getCode(), $exception, $exception->getInvalidMessage(), $exception->getInvalidMessageParameters());
}
return $value;

View File

@@ -102,7 +102,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
return $this->children[$name];
}
throw new InvalidArgumentException(sprintf('The child with the name "%s" does not exist.', $name));
throw new InvalidArgumentException(\sprintf('The child with the name "%s" does not exist.', $name));
}
public function remove(string $name): static

View File

@@ -75,7 +75,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
self::validateName($name);
if (null !== $dataClass && !class_exists($dataClass) && !interface_exists($dataClass, false)) {
throw new InvalidArgumentException(sprintf('Class "%s" not found. Is the "data_class" form option set correctly?', $dataClass));
throw new InvalidArgumentException(\sprintf('Class "%s" not found. Is the "data_class" form option set correctly?', $dataClass));
}
$this->name = (string) $name;
@@ -636,7 +636,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
final public static function validateName(?string $name): void
{
if (!self::isValidName($name)) {
throw new InvalidArgumentException(sprintf('The name "%s" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").', $name));
throw new InvalidArgumentException(\sprintf('The name "%s" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").', $name));
}
}

View File

@@ -58,7 +58,7 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
{
foreach ($errors as $error) {
if (!($error instanceof FormError || $error instanceof self)) {
throw new InvalidArgumentException(sprintf('The errors must be instances of "Symfony\Component\Form\FormError" or "%s". Got: "%s".', __CLASS__, get_debug_type($error)));
throw new InvalidArgumentException(\sprintf('The errors must be instances of "Symfony\Component\Form\FormError" or "%s". Got: "%s".', __CLASS__, get_debug_type($error)));
}
}
@@ -199,7 +199,7 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
public function getChildren(): self
{
if (!$this->hasChildren()) {
throw new LogicException(sprintf('The current element is not iterable. Use "%s" to get the current element.', self::class.'::current()'));
throw new LogicException(\sprintf('The current element is not iterable. Use "%s" to get the current element.', self::class.'::current()'));
}
/** @var self $children */

View File

@@ -33,7 +33,7 @@ class FormRegistry implements FormRegistryInterface
*/
private array $types = [];
private FormTypeGuesserInterface|null|false $guesser = false;
private FormTypeGuesserInterface|false|null $guesser = false;
private ResolvedFormTypeFactoryInterface $resolvedTypeFactory;
private array $checkedTypes = [];
@@ -69,10 +69,10 @@ class FormRegistry implements FormRegistryInterface
if (!$type) {
// Support fully-qualified class names
if (!class_exists($name)) {
throw new InvalidArgumentException(sprintf('Could not load type "%s": class does not exist.', $name));
throw new InvalidArgumentException(\sprintf('Could not load type "%s": class does not exist.', $name));
}
if (!is_subclass_of($name, FormTypeInterface::class)) {
throw new InvalidArgumentException(sprintf('Could not load type "%s": class does not implement "Symfony\Component\Form\FormTypeInterface".', $name));
throw new InvalidArgumentException(\sprintf('Could not load type "%s": class does not implement "Symfony\Component\Form\FormTypeInterface".', $name));
}
$type = new $name();
@@ -94,7 +94,7 @@ class FormRegistry implements FormRegistryInterface
if (isset($this->checkedTypes[$fqcn])) {
$types = implode(' > ', array_merge(array_keys($this->checkedTypes), [$fqcn]));
throw new LogicException(sprintf('Circular reference detected for form type "%s" (%s).', $fqcn, $types));
throw new LogicException(\sprintf('Circular reference detected for form type "%s" (%s).', $fqcn, $types));
}
$this->checkedTypes[$fqcn] = true;

View File

@@ -64,7 +64,7 @@ class FormRenderer implements FormRendererInterface
$resource = $this->engine->getResourceForBlockName($view, $blockName);
if (!$resource) {
throw new LogicException(sprintf('No block "%s" found while rendering the form.', $blockName));
throw new LogicException(\sprintf('No block "%s" found while rendering the form.', $blockName));
}
$viewCacheKey = $view->vars[self::CACHE_KEY_VAR];
@@ -121,7 +121,7 @@ class FormRenderer implements FormRendererInterface
if ($renderOnlyOnce && $view->isRendered()) {
// This is not allowed, because it would result in rendering same IDs multiple times, which is not valid.
throw new BadMethodCallException(sprintf('Field "%s" has already been rendered, save the result of previous render call to a variable and output that instead.', $view->vars['name']));
throw new BadMethodCallException(\sprintf('Field "%s" has already been rendered, save the result of previous render call to a variable and output that instead.', $view->vars['name']));
}
// The cache key for storing the variables and types
@@ -208,10 +208,10 @@ class FormRenderer implements FormRendererInterface
// Escape if no resource exists for this block
if (!$resource) {
if (\count($blockNameHierarchy) !== \count(array_unique($blockNameHierarchy))) {
throw new LogicException(sprintf('Unable to render the form because the block names array contains duplicates: "%s".', implode('", "', array_reverse($blockNameHierarchy))));
throw new LogicException(\sprintf('Unable to render the form because the block names array contains duplicates: "%s".', implode('", "', array_reverse($blockNameHierarchy))));
}
throw new LogicException(sprintf('Unable to render the form as none of the following blocks exist: "%s".', implode('", "', array_reverse($blockNameHierarchy))));
throw new LogicException(\sprintf('Unable to render the form as none of the following blocks exist: "%s".', implode('", "', array_reverse($blockNameHierarchy))));
}
// Merge the passed with the existing attributes

View File

@@ -43,7 +43,7 @@ class NativeRequestHandler implements RequestHandlerInterface
/**
* @return void
*
* @throws Exception\UnexpectedTypeException If the $request is not null
* @throws UnexpectedTypeException If the $request is not null
*/
public function handleRequest(FormInterface $form, mixed $request = null)
{

View File

@@ -43,7 +43,7 @@ class PreloadedExtension implements FormExtensionInterface
public function getType(string $name): FormTypeInterface
{
if (!isset($this->types[$name])) {
throw new InvalidArgumentException(sprintf('The type "%s" cannot be loaded by this extension.', $name));
throw new InvalidArgumentException(\sprintf('The type "%s" cannot be loaded by this extension.', $name));
}
return $this->types[$name];

View File

@@ -75,7 +75,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
try {
$options = $this->getOptionsResolver()->resolve($options);
} catch (ExceptionInterface $e) {
throw new $e(sprintf('An error has occurred resolving the options of the form "%s": ', get_debug_type($this->getInnerType())).$e->getMessage(), $e->getCode(), $e);
throw new $e(\sprintf('An error has occurred resolving the options of the form "%s": ', get_debug_type($this->getInnerType())).$e->getMessage(), $e->getCode(), $e);
}
// Should be decoupled from the specific option at some point

View File

@@ -37,7 +37,7 @@ abstract class FormPerformanceTestCase extends FormIntegrationTestCase
$time = microtime(true) - $s;
if (0 != $this->maxRunningTime && $time > $this->maxRunningTime) {
$this->fail(sprintf('expected running time: <= %s but was: %s', $this->maxRunningTime, $time));
$this->fail(\sprintf('expected running time: <= %s but was: %s', $this->maxRunningTime, $time));
}
$this->expectNotToPerformAssertions();

View File

@@ -31,7 +31,7 @@ trait ValidatorExtensionTrait
}
if (!$this instanceof TypeTestCase) {
throw new \Exception(sprintf('The trait "ValidatorExtensionTrait" can only be added to a class that extends "%s".', TypeTestCase::class));
throw new \Exception(\sprintf('The trait "ValidatorExtensionTrait" can only be added to a class that extends "%s".', TypeTestCase::class));
}
$this->validator = $this->createMock(ValidatorInterface::class);

View File

@@ -39,7 +39,7 @@ abstract class AbstractRequestHandlerTestCase extends TestCase
protected function setUp(): void
{
$this->serverParams = new class() extends ServerParams {
$this->serverParams = new class extends ServerParams {
public ?int $contentLength = null;
public string $postMaxSize = '';

View File

@@ -159,9 +159,9 @@ class DefaultChoiceListFactoryTest extends TestCase
{
$list = $this->factory->createListFromChoices(
new \ArrayIterator([
'Group 1' => ['A' => $this->obj1, 'B' => $this->obj2],
'Group 2' => ['C' => $this->obj3, 'D' => $this->obj4],
])
'Group 1' => ['A' => $this->obj1, 'B' => $this->obj2],
'Group 2' => ['C' => $this->obj3, 'D' => $this->obj4],
])
);
$this->assertObjectListWithGeneratedValues($list);
@@ -728,7 +728,7 @@ class DefaultChoiceListFactoryTest extends TestCase
public function testPassTranslatableInterfaceAsLabelDoesntCastItToString()
{
$message = new class() implements TranslatableInterface {
$message = new class implements TranslatableInterface {
public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
return 'my_message';
@@ -941,7 +941,7 @@ class DefaultChoiceListFactoryTest extends TestCase
'C',
['attr2' => 'value2']
),
]
]
), $view);
}
@@ -987,7 +987,7 @@ class DefaultChoiceListFactoryTest extends TestCase
'Group 2',
[2 => new ChoiceView($this->obj3, '2', 'C')]
),
]
]
), $view);
}

View File

@@ -69,8 +69,8 @@ class CallbackChoiceLoaderTest extends TestCase
public function testLoadValuesForChoicesCastsCallbackItemsToString()
{
$choices = [
(object) ['id' => 2],
(object) ['id' => 3],
(object) ['id' => 2],
(object) ['id' => 3],
];
$value = fn ($item) => $item->id;

View File

@@ -153,7 +153,7 @@ abstract class AbstractDescriptorTestCase extends TestCase
private function getFixtureFilename($name)
{
return sprintf('%s/../../Fixtures/Descriptor/%s.%s', __DIR__, $name, $this->getFormat());
return \sprintf('%s/../../Fixtures/Descriptor/%s.%s', __DIR__, $name, $this->getFormat());
}
}

View File

@@ -1895,8 +1895,8 @@ class ChoiceTypeTest extends BaseTypeTestCase
{
$this->assertInstanceOf(
FormInterface::class, $this->factory->createNamed('name', static::TESTED_TYPE, null, [
'choices' => [],
]));
'choices' => [],
]));
}
public function testInitializeWithDefaultObjectChoice()

View File

@@ -31,7 +31,7 @@ class ChoiceTypeTranslationTest extends TypeTestCase
{
$translator = $this->createMock(TranslatorInterface::class);
$translator->expects($this->any())->method('trans')
->willReturnCallback(fn ($key, $params) => strtr(sprintf('Translation of: %s', $key), $params)
->willReturnCallback(fn ($key, $params) => strtr(\sprintf('Translation of: %s', $key), $params)
);
return array_merge(parent::getExtensions(), [new CoreExtension(null, null, $translator)]);

View File

@@ -156,24 +156,24 @@ class FormTypeTest extends BaseTypeTestCase
{
$this->assertInstanceOf(
FormBuilderInterface::class, $this->factory->createBuilder(static::TESTED_TYPE, null, [
'data_class' => null,
]));
'data_class' => null,
]));
}
public function testDataClassMayBeAbstractClass()
{
$this->assertInstanceOf(
FormBuilderInterface::class, $this->factory->createBuilder(static::TESTED_TYPE, null, [
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor',
]));
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor',
]));
}
public function testDataClassMayBeInterface()
{
$this->assertInstanceOf(
FormBuilderInterface::class, $this->factory->createBuilder(static::TESTED_TYPE, null, [
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface',
]));
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface',
]));
}
public function testDataClassMustBeValidClassOrInterface()
@@ -402,7 +402,7 @@ class FormTypeTest extends BaseTypeTestCase
// referenceCopy has a getter that returns a copy
'referenceCopy' => [
'firstName' => 'Foo',
],
],
]);
$this->assertEquals('Foo', $author->getReferenceCopy()->firstName);
@@ -680,8 +680,8 @@ $ref2
public function testPassZeroLabelToView()
{
$view = $this->factory->create(static::TESTED_TYPE, null, [
'label' => '0',
])
'label' => '0',
])
->createView();
$this->assertSame('0', $view->vars['label']);

View File

@@ -198,7 +198,7 @@ class RepeatedTypeTest extends BaseTypeTestCase
'type' => TextType::class,
'options' => [
'empty_data' => $emptyData,
]
],
]);
$form->submit($submittedData);

View File

@@ -71,7 +71,7 @@ class FormDataCollectorTest extends TestCase
],
'errors' => [],
'children' => [],
];
];
$formData = [
'id' => 'name',
@@ -87,11 +87,11 @@ class FormDataCollectorTest extends TestCase
'norm' => null,
],
'errors' => [],
'has_children_error' => false,
'children' => [
'child' => $childFormData,
],
];
'has_children_error' => false,
'children' => [
'child' => $childFormData,
],
];
$this->assertEquals([
'forms' => [
@@ -102,7 +102,7 @@ class FormDataCollectorTest extends TestCase
spl_object_hash($this->childForm) => $childFormData,
],
'nb_errors' => 0,
], $this->dataCollector->getData());
], $this->dataCollector->getData());
}
public function testBuildMultiplePreliminaryFormTrees()

View File

@@ -362,8 +362,7 @@ class FormDataExtractorTest extends TestCase
]
EODUMP;
}
$this->assertDumpMatchesFormat($expectedFormat
,
$this->assertDumpMatchesFormat($expectedFormat,
$this->dataExtractor->extractSubmittedData($form)
);
}

View File

@@ -44,7 +44,7 @@ class DependencyInjectionExtensionTest extends TestCase
public function testThrowExceptionForInvalidExtendedType()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf('The extended type "unmatched" specified for the type extension class "%s" does not match any of the actual extended types (["test"]).', TestTypeExtension::class));
$this->expectExceptionMessage(\sprintf('The extended type "unmatched" specified for the type extension class "%s" does not match any of the actual extended types (["test"]).', TestTypeExtension::class));
$extensions = [
'unmatched' => new \ArrayIterator([new TestTypeExtension()]),

View File

@@ -88,9 +88,9 @@ class FormValidatorFunctionalTest extends TestCase
public function testNonCompositeConstraintValidatedOnce()
{
$form = $this->formFactory->create(TextType::class, null, [
'constraints' => [new NotBlank(['groups' => ['foo', 'bar']])],
'validation_groups' => ['foo', 'bar'],
]);
'constraints' => [new NotBlank(['groups' => ['foo', 'bar']])],
'validation_groups' => ['foo', 'bar'],
]);
$form->submit('');
$violations = $this->validator->validate($form);

View File

@@ -184,8 +184,8 @@ class FormValidatorTest extends ConstraintValidatorTestCase
$object = new \stdClass();
$form = $this->getBuilder('name', '\stdClass', [
'validation_groups' => [],
])
'validation_groups' => [],
])
->setData($object)
->setCompound(true)
->setDataMapper(new DataMapper())
@@ -256,12 +256,12 @@ class FormValidatorTest extends ConstraintValidatorTestCase
$object = new \stdClass();
$form = $this->getBuilder('name', '\stdClass', [
'invalid_message' => 'invalid_message_key',
// Invalid message parameters must be supported, because the
// invalid message can be a translation key
// see https://github.com/symfony/symfony/issues/5144
'invalid_message_parameters' => ['{{ foo }}' => 'bar'],
])
'invalid_message' => 'invalid_message_key',
// Invalid message parameters must be supported, because the
// invalid message can be a translation key
// see https://github.com/symfony/symfony/issues/5144
'invalid_message_parameters' => ['{{ foo }}' => 'bar'],
])
->setData($object)
->addViewTransformer(new CallbackTransformer(
static fn ($data) => $data,
@@ -292,13 +292,13 @@ class FormValidatorTest extends ConstraintValidatorTestCase
$object = new \stdClass();
$form = $this->getBuilder('name', '\stdClass', [
'invalid_message' => 'invalid_message_key',
// Invalid message parameters must be supported, because the
// invalid message can be a translation key
// see https://github.com/symfony/symfony/issues/5144
'invalid_message_parameters' => ['{{ foo }}' => 'bar'],
'validation_groups' => [],
])
'invalid_message' => 'invalid_message_key',
// Invalid message parameters must be supported, because the
// invalid message can be a translation key
// see https://github.com/symfony/symfony/issues/5144
'invalid_message_parameters' => ['{{ foo }}' => 'bar'],
'validation_groups' => [],
])
->setData($object)
->addViewTransformer(new CallbackTransformer(
static fn ($data) => $data,

View File

@@ -50,7 +50,7 @@ class ValidatorTypeGuesserTest extends TestCase
/**
* @var MetadataFactoryInterface
*/
private \Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory $metadataFactory;
private FakeMetadataFactory $metadataFactory;
protected function setUp(): void
{

View File

@@ -173,10 +173,10 @@ class FormFactoryTest extends TestCase
class ConfigurableFormTypeGuesser implements FormTypeGuesserInterface
{
private ?\Symfony\Component\Form\Guess\TypeGuess $typeGuess = null;
private ?\Symfony\Component\Form\Guess\ValueGuess $requiredGuess = null;
private ?\Symfony\Component\Form\Guess\ValueGuess $maxLengthGuess = null;
private ?\Symfony\Component\Form\Guess\ValueGuess $patternGuess = null;
private ?TypeGuess $typeGuess = null;
private ?ValueGuess $requiredGuess = null;
private ?ValueGuess $maxLengthGuess = null;
private ?ValueGuess $patternGuess = null;
public function guessType($class, $property): ?TypeGuess
{

View File

@@ -168,8 +168,8 @@ class NativeRequestHandlerTest extends AbstractRequestHandlerTestCase
$form = $this->createForm('param1', 'POST');
$this->setRequestData('GET', [
'param1' => 'DATA',
]);
'param1' => 'DATA',
]);
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';

View File

@@ -100,7 +100,7 @@ class ResolvedFormTypeTest extends TestCase
public function testFailsCreateBuilderOnInvalidFormOptionsResolution()
{
$this->expectException(MissingOptionsException::class);
$this->expectExceptionMessage(sprintf('An error has occurred resolving the options of the form "%s": The required option "foo" is missing.', UsageTrackingFormType::class));
$this->expectExceptionMessage(\sprintf('An error has occurred resolving the options of the form "%s": The required option "foo" is missing.', UsageTrackingFormType::class));
$this->resolvedType->createBuilder($this->formFactory, 'name');
}

View File

@@ -26,7 +26,7 @@ class TranslationFilesTest extends TestCase
$errors = XliffUtils::validateSchema($document);
$this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
$this->assertCount(0, $errors, \sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
}
/**
@@ -39,7 +39,7 @@ class TranslationFilesTest extends TestCase
$errors = XliffUtils::validateSchema($document);
$this->assertCount(0, $errors, sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
$this->assertCount(0, $errors, \sprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
}
public static function provideTranslationFiles()

View File

@@ -503,9 +503,9 @@ class SimpleFormTest extends TestCase
{
$form = $this->getBuilder()
->addModelTransformer(new FixedDataTransformer([
'' => '',
1 => 23,
]))
'' => '',
1 => 23,
]))
->getForm();
$form->setData(1);

View File

@@ -56,7 +56,7 @@ class StringUtilTest extends TestCase
['0020'],
['00A0'],
['1680'],
// ['180E'],
// ['180E'],
['2000'],
['2001'],
['2002'],

View File

@@ -18,7 +18,7 @@ trait VersionAwareTest
protected function requiresFeatureSet(int $requiredFeatureSetVersion)
{
if ($requiredFeatureSetVersion > static::$supportedFeatureSetVersion) {
$this->markTestSkipped(sprintf('Test requires features from symfony/form %.2f but only version %.2f is supported.', $requiredFeatureSetVersion / 100, static::$supportedFeatureSetVersion / 100));
$this->markTestSkipped(\sprintf('Test requires features from symfony/form %.2f but only version %.2f is supported.', $requiredFeatureSetVersion / 100, static::$supportedFeatureSetVersion / 100));
}
}
}

View File

@@ -112,7 +112,7 @@ class OrderedHashMap implements \ArrayAccess, \IteratorAggregate, \Countable
public function offsetGet(mixed $key): mixed
{
if (!isset($this->elements[$key])) {
throw new \OutOfBoundsException(sprintf('The offset "%s" does not exist.', $key));
throw new \OutOfBoundsException(\sprintf('The offset "%s" does not exist.', $key));
}
return $this->elements[$key];