Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 289a768

Browse filesBrowse files
committed
[Form] Backport type fixes
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent c9e4c33 commit 289a768
Copy full SHA for 289a768
Expand file treeCollapse file tree

25 files changed

+131
-148
lines changed

‎src/Symfony/Component/Form/AbstractExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/AbstractExtension.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ abstract class AbstractExtension implements FormExtensionInterface
2222
/**
2323
* The types provided by this extension.
2424
*
25-
* @var FormTypeInterface[] An array of FormTypeInterface
25+
* @var FormTypeInterface[]
2626
*/
2727
private $types;
2828

2929
/**
3030
* The type extensions provided by this extension.
3131
*
32-
* @var FormTypeExtensionInterface[] An array of FormTypeExtensionInterface
32+
* @var FormTypeExtensionInterface[][]
3333
*/
3434
private $typeExtensions;
3535

@@ -153,7 +153,7 @@ private function initTypes()
153153

154154
foreach ($this->loadTypes() as $type) {
155155
if (!$type instanceof FormTypeInterface) {
156-
throw new UnexpectedTypeException($type, 'Symfony\Component\Form\FormTypeInterface');
156+
throw new UnexpectedTypeException($type, FormTypeInterface::class);
157157
}
158158

159159
$this->types[\get_class($type)] = $type;
@@ -172,7 +172,7 @@ private function initTypeExtensions()
172172

173173
foreach ($this->loadTypeExtensions() as $extension) {
174174
if (!$extension instanceof FormTypeExtensionInterface) {
175-
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormTypeExtensionInterface');
175+
throw new UnexpectedTypeException($extension, FormTypeExtensionInterface::class);
176176
}
177177

178178
if (method_exists($extension, 'getExtendedTypes')) {
@@ -204,7 +204,7 @@ private function initTypeGuesser()
204204

205205
$this->typeGuesser = $this->loadTypeGuesser();
206206
if (null !== $this->typeGuesser && !$this->typeGuesser instanceof FormTypeGuesserInterface) {
207-
throw new UnexpectedTypeException($this->typeGuesser, 'Symfony\Component\Form\FormTypeGuesserInterface');
207+
throw new UnexpectedTypeException($this->typeGuesser, FormTypeGuesserInterface::class);
208208
}
209209
}
210210
}

‎src/Symfony/Component/Form/AbstractRendererEngine.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/AbstractRendererEngine.php
+19-1Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,29 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface
2323
*/
2424
public const CACHE_KEY_VAR = 'cache_key';
2525

26+
/**
27+
* @var array
28+
*/
2629
protected $defaultThemes;
30+
31+
/**
32+
* @var array[]
33+
*/
2734
protected $themes = [];
35+
36+
/**
37+
* @var bool[]
38+
*/
2839
protected $useDefaultThemes = [];
40+
41+
/**
42+
* @var array[]
43+
*/
2944
protected $resources = [];
3045

46+
/**
47+
* @var array<array<int|false>>
48+
*/
3149
private $resourceHierarchyLevels = [];
3250

3351
/**
@@ -127,7 +145,7 @@ abstract protected function loadResourceForBlockName($cacheKey, FormView $view,
127145
*
128146
* @see getResourceForBlockHierarchy()
129147
*/
130-
private function loadResourceForBlockNameHierarchy(string $cacheKey, FormView $view, array $blockNameHierarchy, $hierarchyLevel): bool
148+
private function loadResourceForBlockNameHierarchy(string $cacheKey, FormView $view, array $blockNameHierarchy, int $hierarchyLevel): bool
131149
{
132150
$blockName = $blockNameHierarchy[$hierarchyLevel];
133151

‎src/Symfony/Component/Form/Button.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Button.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Button implements \IteratorAggregate, FormInterface
2323
{
2424
/**
25-
* @var FormInterface
25+
* @var FormInterface|null
2626
*/
2727
private $parent;
2828

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ abstract class BaseDateTimeTransformer implements DataTransformerInterface
2929
protected $outputTimezone;
3030

3131
/**
32-
* @param string $inputTimezone The name of the input timezone
33-
* @param string $outputTimezone The name of the output timezone
32+
* @param string|null $inputTimezone The name of the input timezone
33+
* @param string|null $outputTimezone The name of the output timezone
3434
*
3535
* @throws InvalidArgumentException if a timezone is not valid
3636
*/

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
4343
private $pad;
4444

4545
/**
46-
* @param string[] $fields The date fields
47-
* @param bool $pad Whether to use padding
46+
* @param string[]|null $fields The date fields
47+
* @param bool $pad Whether to use padding
4848
*/
4949
public function __construct(array $fields = null, bool $pad = false)
5050
{
51-
if (null === $fields) {
52-
$fields = ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'invert'];
53-
}
54-
$this->fields = $fields;
51+
$this->fields = $fields ?? ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'invert'];
5552
$this->pad = $pad;
5653
}
5754

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php
+5-10Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,20 @@
2222
class DateTimeToArrayTransformer extends BaseDateTimeTransformer
2323
{
2424
private $pad;
25-
2625
private $fields;
2726
private $referenceDate;
2827

2928
/**
30-
* @param string $inputTimezone The input timezone
31-
* @param string $outputTimezone The output timezone
32-
* @param array $fields The date fields
33-
* @param bool $pad Whether to use padding
29+
* @param string|null $inputTimezone The input timezone
30+
* @param string|null $outputTimezone The output timezone
31+
* @param string[]|null $fields The date fields
32+
* @param bool $pad Whether to use padding
3433
*/
3534
public function __construct(string $inputTimezone = null, string $outputTimezone = null, array $fields = null, bool $pad = false, \DateTimeInterface $referenceDate = null)
3635
{
3736
parent::__construct($inputTimezone, $outputTimezone);
3837

39-
if (null === $fields) {
40-
$fields = ['year', 'month', 'day', 'hour', 'minute', 'second'];
41-
}
42-
43-
$this->fields = $fields;
38+
$this->fields = $fields ?? ['year', 'month', 'day', 'hour', 'minute', 'second'];
4439
$this->pad = $pad;
4540
$this->referenceDate = $referenceDate ?? new \DateTimeImmutable('1970-01-01 00:00:00');
4641
}

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
3030
/**
3131
* @see BaseDateTimeTransformer::formats for available format options
3232
*
33-
* @param string $inputTimezone The name of the input timezone
34-
* @param string $outputTimezone The name of the output timezone
35-
* @param int $dateFormat The date format
36-
* @param int $timeFormat The time format
37-
* @param int $calendar One of the \IntlDateFormatter calendar constants
38-
* @param string $pattern A pattern to pass to \IntlDateFormatter
33+
* @param string|null $inputTimezone The name of the input timezone
34+
* @param string|null $outputTimezone The name of the output timezone
35+
* @param int|null $dateFormat The date format
36+
* @param int|null $timeFormat The time format
37+
* @param int $calendar One of the \IntlDateFormatter calendar constants
38+
* @param string|null $pattern A pattern to pass to \IntlDateFormatter
3939
*
4040
* @throws UnexpectedTypeException If a format is not supported or if a timezone is not a string
4141
*/
@@ -70,7 +70,7 @@ public function __construct(string $inputTimezone = null, string $outputTimezone
7070
*
7171
* @param \DateTimeInterface $dateTime A DateTimeInterface object
7272
*
73-
* @return string|array Localized date string/array
73+
* @return string Localized date string
7474
*
7575
* @throws TransformationFailedException if the given value is not a \DateTimeInterface
7676
* or if the date could not be transformed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
4444
*
4545
* @see \DateTime::format() for supported formats
4646
*
47-
* @param string $inputTimezone The name of the input timezone
48-
* @param string $outputTimezone The name of the output timezone
49-
* @param string $format The date format
47+
* @param string|null $inputTimezone The name of the input timezone
48+
* @param string|null $outputTimezone The name of the output timezone
49+
* @param string $format The date format
5050
*/
5151
public function __construct(string $inputTimezone = null, string $outputTimezone = null, string $format = 'Y-m-d H:i:s')
5252
{

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php
+2-14Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,9 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
2525

2626
public function __construct(?int $scale = 2, ?bool $grouping = true, ?int $roundingMode = self::ROUND_HALF_UP, ?int $divisor = 1)
2727
{
28-
if (null === $grouping) {
29-
$grouping = true;
30-
}
31-
32-
if (null === $scale) {
33-
$scale = 2;
34-
}
35-
36-
parent::__construct($scale, $grouping, $roundingMode);
37-
38-
if (null === $divisor) {
39-
$divisor = 1;
40-
}
28+
parent::__construct($scale ?? 2, $grouping ?? true, $roundingMode);
4129

42-
$this->divisor = $divisor;
30+
$this->divisor = $divisor ?? 1;
4331
}
4432

4533
/**

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,9 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
8181

8282
public function __construct(int $scale = null, ?bool $grouping = false, ?int $roundingMode = self::ROUND_HALF_UP, string $locale = null)
8383
{
84-
if (null === $grouping) {
85-
$grouping = false;
86-
}
87-
88-
if (null === $roundingMode) {
89-
$roundingMode = self::ROUND_HALF_UP;
90-
}
91-
9284
$this->scale = $scale;
93-
$this->grouping = $grouping;
94-
$this->roundingMode = $roundingMode;
85+
$this->grouping = $grouping ?? false;
86+
$this->roundingMode = $roundingMode ?? self::ROUND_HALF_UP;
9587
$this->locale = $locale;
9688
}
9789

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php
+1-8Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,10 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
3737
/**
3838
* @see self::$types for a list of supported types
3939
*
40-
* @param int $scale The scale
41-
* @param string $type One of the supported types
42-
*
4340
* @throws UnexpectedTypeException if the given value of type is unknown
4441
*/
4542
public function __construct(int $scale = null, string $type = null)
4643
{
47-
if (null === $scale) {
48-
$scale = 0;
49-
}
50-
5144
if (null === $type) {
5245
$type = self::FRACTIONAL;
5346
}
@@ -57,7 +50,7 @@ public function __construct(int $scale = null, string $type = null)
5750
}
5851

5952
$this->type = $type;
60-
$this->scale = $scale;
53+
$this->scale = $scale ?? 0;
6154
}
6255

6356
/**

‎src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class DateIntervalType extends AbstractType
3030
{
31-
private $timeParts = [
31+
private const TIME_PARTS = [
3232
'years',
3333
'months',
3434
'weeks',
@@ -96,7 +96,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
9696
if ('single_text' === $options['widget']) {
9797
$builder->addViewTransformer(new DateIntervalToStringTransformer($format));
9898
} else {
99-
foreach ($this->timeParts as $part) {
99+
foreach (self::TIME_PARTS as $part) {
100100
if ($options['with_'.$part]) {
101101
$childOptions = [
102102
'error_bubbling' => true,
@@ -157,7 +157,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
157157
'widget' => $options['widget'],
158158
'with_invert' => $options['with_invert'],
159159
];
160-
foreach ($this->timeParts as $part) {
160+
foreach (self::TIME_PARTS as $part) {
161161
$vars['with_'.$part] = $options['with_'.$part];
162162
}
163163
$view->vars = array_replace($view->vars, $vars);
@@ -168,7 +168,6 @@ public function buildView(FormView $view, FormInterface $form, array $options)
168168
*/
169169
public function configureOptions(OptionsResolver $resolver)
170170
{
171-
$timeParts = $this->timeParts;
172171
$compound = function (Options $options) {
173172
return 'single_text' !== $options['widget'];
174173
};
@@ -180,14 +179,14 @@ public function configureOptions(OptionsResolver $resolver)
180179
return $options['required'] ? null : '';
181180
};
182181

183-
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault, $timeParts) {
182+
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
184183
if (\is_array($placeholder)) {
185184
$default = $placeholderDefault($options);
186185

187-
return array_merge(array_fill_keys($timeParts, $default), $placeholder);
186+
return array_merge(array_fill_keys(self::TIME_PARTS, $default), $placeholder);
188187
}
189188

190-
return array_fill_keys($timeParts, $placeholder);
189+
return array_fill_keys(self::TIME_PARTS, $placeholder);
191190
};
192191

193192
$labelsNormalizer = function (Options $options, array $labels) {

‎src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class DateType extends AbstractType
3939
];
4040

4141
private const WIDGETS = [
42-
'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
43-
'choice' => 'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
42+
'text' => TextType::class,
43+
'choice' => ChoiceType::class,
4444
];
4545

4646
/**

‎src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
class TimeType extends AbstractType
3030
{
3131
private const WIDGETS = [
32-
'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
33-
'choice' => 'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
32+
'text' => TextType::class,
33+
'choice' => ChoiceType::class,
3434
];
3535

3636
/**

‎src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Form\AbstractTypeExtension;
1515
use Symfony\Component\Form\Extension\Core\Type\FormType;
16+
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
1617
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
1718
use Symfony\Component\Form\FormBuilderInterface;
1819
use Symfony\Component\Form\FormInterface;
@@ -83,7 +84,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
8384
$tokenId = $options['csrf_token_id'] ?: ($form->getName() ?: \get_class($form->getConfig()->getType()->getInnerType()));
8485
$data = (string) $options['csrf_token_manager']->getToken($tokenId);
8586

86-
$csrfForm = $factory->createNamed($options['csrf_field_name'], 'Symfony\Component\Form\Extension\Core\Type\HiddenType', $data, [
87+
$csrfForm = $factory->createNamed($options['csrf_field_name'], HiddenType::class, $data, [
8788
'block_prefix' => 'csrf_token',
8889
'mapped' => false,
8990
]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.