Skip to content

Commit 2d867d6

Browse files
Use ??= more
1 parent 6ef363b commit 2d867d6

File tree

12 files changed

+15
-54
lines changed

12 files changed

+15
-54
lines changed

ChoiceList/Factory/DefaultChoiceListFactory.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public function createView(ChoiceListInterface $list, array|callable $preferredC
7474
}
7575

7676
// The names are generated from an incrementing integer by default
77-
if (null === $index) {
78-
$index = 0;
79-
}
77+
$index ??= 0;
8078

8179
// If $groupBy is a callable returning a string
8280
// choices are added to the group with the name returned by the callable.

Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ private function normalizeAndSortOptionsColumns(array $options): array
194194

195195
private function formatClassLink(string $class, string $text = null): string
196196
{
197-
if (null === $text) {
198-
$text = $class;
199-
}
197+
$text ??= $class;
200198

201199
if ('' === $fileLink = $this->getFileLink($class)) {
202200
return $text;

Extension/Core/DataMapper/CheckboxListMapper.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ class CheckboxListMapper implements DataMapperInterface
2727
{
2828
public function mapDataToForms(mixed $choices, \Traversable $checkboxes)
2929
{
30-
if (null === $choices) {
31-
$choices = [];
32-
}
33-
34-
if (!\is_array($choices)) {
30+
if (!\is_array($choices ??= [])) {
3531
throw new UnexpectedTypeException($choices, 'array');
3632
}
3733

Extension/Core/DataTransformer/ArrayToPartsTransformer.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ public function __construct(array $partMapping)
3030

3131
public function transform(mixed $array): mixed
3232
{
33-
if (null === $array) {
34-
$array = [];
35-
}
36-
37-
if (!\is_array($array)) {
33+
if (!\is_array($array ??= [])) {
3834
throw new TransformationFailedException('Expected an array.');
3935
}
4036

Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@ public function __construct(string $inputTimezone = null, string $outputTimezone
4545
{
4646
parent::__construct($inputTimezone, $outputTimezone);
4747

48-
if (null === $dateFormat) {
49-
$dateFormat = \IntlDateFormatter::MEDIUM;
50-
}
51-
52-
if (null === $timeFormat) {
53-
$timeFormat = \IntlDateFormatter::SHORT;
54-
}
48+
$dateFormat ??= \IntlDateFormatter::MEDIUM;
49+
$timeFormat ??= \IntlDateFormatter::SHORT;
5550

5651
if (!\in_array($dateFormat, self::$formats, true)) {
5752
throw new UnexpectedTypeException($dateFormat, implode('", "', self::$formats));

Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
4848
*/
4949
public function __construct(int $scale = null, string $type = null, int $roundingMode = \NumberFormatter::ROUND_HALFUP, bool $html5Format = false)
5050
{
51-
if (null === $type) {
52-
$type = self::FRACTIONAL;
53-
}
51+
$type ??= self::FRACTIONAL;
5452

5553
if (!\in_array($type, self::$types, true)) {
5654
throw new UnexpectedTypeException($type, implode('", "', self::$types));

Extension/Core/EventListener/MergeCollectionListener.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ public static function getSubscribedEvents(): array
4444
public function onSubmit(FormEvent $event)
4545
{
4646
$dataToMergeInto = $event->getForm()->getNormData();
47-
$data = $event->getData();
48-
49-
if (null === $data) {
50-
$data = [];
51-
}
47+
$data = $event->getData() ?? [];
5248

5349
if (!\is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
5450
throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');

Extension/Core/EventListener/ResizeFormListener.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ public static function getSubscribedEvents(): array
5353
public function preSetData(FormEvent $event)
5454
{
5555
$form = $event->getForm();
56-
$data = $event->getData();
57-
58-
if (null === $data) {
59-
$data = [];
60-
}
56+
$data = $event->getData() ?? [];
6157

6258
if (!\is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
6359
throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
@@ -109,16 +105,12 @@ public function preSubmit(FormEvent $event)
109105
public function onSubmit(FormEvent $event)
110106
{
111107
$form = $event->getForm();
112-
$data = $event->getData();
108+
$data = $event->getData() ?? [];
113109

114110
// At this point, $data is an array or an array-like object that already contains the
115111
// new entries, which were added by the data mapper. The data mapper ignores existing
116112
// entries, so we need to manually unset removed entries in the collection.
117113

118-
if (null === $data) {
119-
$data = [];
120-
}
121-
122114
if (!\is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
123115
throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
124116
}

Extension/Core/Type/BaseType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
5454
$uniqueBlockPrefix = '_'.$blockName;
5555
}
5656

57-
if (null === $translationDomain) {
58-
$translationDomain = $view->parent->vars['translation_domain'];
59-
}
57+
$translationDomain ??= $view->parent->vars['translation_domain'];
6058

6159
$labelTranslationParameters = array_merge($view->parent->vars['label_translation_parameters'], $labelTranslationParameters);
6260
$attrTranslationParameters = array_merge($view->parent->vars['attr_translation_parameters'], $attrTranslationParameters);

Extension/Validator/ViolationMapper/ViolationMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
176176
if (false !== $label) {
177177
if (null === $label && null !== $this->formRenderer) {
178178
$label = $this->formRenderer->humanize($scope->getName());
179-
} elseif (null === $label) {
180-
$label = $scope->getName();
179+
} else {
180+
$label ??= $scope->getName();
181181
}
182182

183183
if (null !== $this->translator) {

0 commit comments

Comments
 (0)