Problem/Motivation
For example,
A: in core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php
, in function getNormalization
, $base['links'] = $base['links'] ?? $this->serializer->normalize($object->getLinks(), $format, $context)->omitIfEmpty();
could be changed in, $base['links'] ??= $this->serializer->normalize($object->getLinks(), $format, $context)->omitIfEmpty();
B: in core/modules/layout_discovery/layout_discovery.module
, in function template_preprocess_layout
,
if (!isset($variables['content'][$name]['#attributes'])) {
$variables['content'][$name]['#attributes'] = [];
}
could be changed in, $variables['content'][$name]['#attributes'] ??= [];
Steps to reproduce
Proposed resolution
From #2 in #3418494: Use null coalescing assignment operator: case $A = $A ?? $B;,
.... assume there are many similar changes we could make across all of core, and ideally a coding standards sniff we could enable to prevent this code from creeping back in.
Ideally we would change all instances of this across core in one go,
Therefore trying to do this with some sed commands.
Remaining tasks
A: #3418494: Use null coalescing assignment operator: case $A = $A ?? $B;
B: #3423310: Use null coalescing assignment operator: multilignes case.