8000 [Form] Backport type fixes · Seldaek/symfony@289a768 · GitHub
[go: up one dir, main page]

Skip to content

Commit 289a768

Browse files
committed
[Form] Backport type fixes
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent c9e4c33 commit 289a768

25 files changed

+131
-148
lines changed

src/Symfony/Component/Form/AbstractExtension.php

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

0 commit comments

Comments
 (0)
0