Skip to content

Commit 33c3669

Browse files
[5.3] Use Null Coalescing Assignment Operator For Components (joomla#44878)
* Fix alignment, thanks @QuyTon * Update php-cs-fixer rule, correctly align ??= operator * Fix additional CS --------- Co-authored-by: Harald Leithner <[email protected]>
1 parent a654edf commit 33c3669

File tree

21 files changed

+39
-39
lines changed

21 files changed

+39
-39
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
// Arrays on multiline should have a trailing comma
7777
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
7878
// Align elements in multiline array and variable declarations on new lines below each other
79-
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align']],
79+
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align', '??=' => 'align']],
8080
// The "No break" comment in switch statements
8181
'no_break_comment' => ['comment_text' => 'No break'],
8282
// Remove unused imports

administrator/components/com_content/src/Event/Model/FeatureEvent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function __construct($name, array $arguments = [])
4949
if (!\array_key_exists('extensionName', $arguments) || !\array_key_exists('section', $arguments)) {
5050
$parts = explode('.', $arguments['extension']);
5151

52-
$arguments['extensionName'] = $arguments['extensionName'] ?? $parts[0];
53-
$arguments['section'] = $arguments['section'] ?? $parts[1];
52+
$arguments['extensionName'] ??= $parts[0];
53+
$arguments['section'] ??= $parts[1];
5454
}
5555

5656
if (!isset($arguments['pks']) || !\is_array($arguments['pks'])) {

administrator/components/com_content/src/Model/ArticleModel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ArticleModel extends AdminModel implements WorkflowModelInterface
106106
*/
107107
public function __construct($config = [], ?MVCFactoryInterface $factory = null, ?FormFactoryInterface $formFactory = null)
108108
{
109-
$config['events_map'] = $config['events_map'] ?? [];
109+
$config['events_map'] ??= [];
110110

111111
$config['events_map'] = array_merge(
112112
['featured' => 'content'],
@@ -117,9 +117,9 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null,
117117

118118
// Set the featured status change events
119119
$this->event_before_change_featured = $config['event_before_change_featured'] ?? $this->event_before_change_featured;
120-
$this->event_before_change_featured = $this->event_before_change_featured ?? 'onContentBeforeChangeFeatured';
120+
$this->event_before_change_featured ??= 'onContentBeforeChangeFeatured';
121121
$this->event_after_change_featured = $config['event_after_change_featured'] ?? $this->event_after_change_featured;
122-
$this->event_after_change_featured = $this->event_after_change_featured ?? 'onContentAfterChangeFeatured';
122+
$this->event_after_change_featured ??= 'onContentAfterChangeFeatured';
123123

124124
$this->setUpWorkflow('com_content.article');
125125
}

administrator/components/com_menus/src/Helper/MenusHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public static function getMenuItems($menutype, $enabledOnly = false, $exclude =
368368
if ($menuitem->link = \in_array($menuitem->type, ['separator', 'heading', 'container']) ? '#' : trim($menuitem->link)) {
369369
$menuitem->submenu = [];
370370
$menuitem->class = $menuitem->img ?? '';
371-
$menuitem->scope = $menuitem->scope ?? null;
371+
$menuitem->scope ??= null;
372372
$menuitem->target = $menuitem->browserNav ? '_blank' : '';
373373
}
374374

@@ -750,7 +750,7 @@ public static function preprocess($item)
750750

751751
if ($item->link = \in_array($item->type, ['separator', 'heading', 'container']) ? '#' : trim($item->link)) {
752752
$item->class = $item->img ?? '';
753-
$item->scope = $item->scope ?? null;
753+
$item->scope ??= null;
754754
$item->target = $item->browserNav ? '_blank' : '';
755755
}
756756
}

administrator/components/com_menus/src/Model/ItemModel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,10 @@ protected function loadFormData()
579579
if (empty($data['id'])) {
580580
// Get selected fields
581581
$filters = Factory::getApplication()->getUserState('com_menus.items.filter');
582-
$data['parent_id'] = $data['parent_id'] ?? ($filters['parent_id'] ?? null);
583-
$data['published'] = $data['published'] ?? ($filters['published'] ?? null);
584-
$data['language'] = $data['language'] ?? ($filters['language'] ?? null);
585-
$data['access'] = $data['access'] ?? ($filters['access'] ?? Factory::getApplication()->get('access'));
582+
$data['parent_id'] ??= $filters['parent_id'] ?? null;
583+
$data['published'] ??= $filters['published'] ?? null;
584+
$data['language'] ??= $filters['language'] ?? null;
585+
$data['access'] ??= $filters['access'] ?? Factory::getApplication()->get('access');
586586
}
587587

588588
if (isset($data['menutype']) && !$this->getState('item.menutypeid')) {

administrator/components/com_menus/src/View/Items/HtmlView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function display($tpl = null)
177177
}
178178
}
179179

180-
$vars['layout'] = $vars['layout'] ?? 'default';
180+
$vars['layout'] ??= 'default';
181181

182182
// Attempt to load the layout xml file.
183183
// If Alternative Menu Item, get template folder for layout file

administrator/components/com_scheduler/src/Helper/ExecRuleHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function nextExec(bool $string = true, bool $basisNow = false)
163163
private function dateTimeToSql(\DateTime $dateTime): string
164164
{
165165
static $db;
166-
$db = $db ?? Factory::getContainer()->get(DatabaseInterface::class);
166+
$db ??= Factory::getContainer()->get(DatabaseInterface::class);
167167

168168
return $dateTime->format($db->getDateFormat());
169169
}

administrator/components/com_scheduler/src/Model/TaskModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class TaskModel extends AdminModel
119119
*/
120120
public function __construct($config = [], ?MVCFactoryInterface $factory = null, ?FormFactoryInterface $formFactory = null)
121121
{
122-
$config['events_map'] = $config['events_map'] ?? [];
122+
$config['events_map'] ??= [];
123123

124124
$config['events_map'] = array_merge(
125125
[
@@ -631,7 +631,7 @@ public function save($data): bool
631631

632632
// If no params, we set as empty array.
633633
// ? Is this the right place to do this
634-
$data['params'] = $data['params'] ?? [];
634+
$data['params'] ??= [];
635635

636636
// Parent method takes care of saving to the table
637637
return parent::save($data);

administrator/components/com_scheduler/src/Task/Task.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function run(): bool
207207
}
208208

209209
$this->snapshot['status'] = Status::RUNNING;
210-
$this->snapshot['taskStart'] = $this->snapshot['taskStart'] ?? microtime(true);
210+
$this->snapshot['taskStart'] ??= microtime(true);
211211
$this->snapshot['netDuration'] = 0;
212212

213213
/** @var ExecuteTaskEvent $event */

administrator/components/com_users/src/Controller/MethodsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function disable($cachable = false, $urlparams = []): void
7575
$user = ($userId === null)
7676
? $this->app->getIdentity()
7777
: $this->getUserFactory()->loadUserById($userId);
78-
$user = $user ?? $this->getUserFactory()->loadUserById(0);
78+
$user ??= $this->getUserFactory()->loadUserById(0);
7979

8080
if (!MfaHelper::canDeleteMethod($user)) {
8181
throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);
@@ -127,7 +127,7 @@ public function display($cachable = false, $urlparams = []): void
127127
$user = ($userId === null)
128128
? $this->app->getIdentity()
129129
: $this->getUserFactory()->loadUserById($userId);
130-
$user = $user ?? $this->getUserFactory()->loadUserById(0);
130+
$user ??= $this->getUserFactory()->loadUserById(0);
131131

132132
if (!MfaHelper::canShowConfigurationInterface($user)) {
133133
throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);
@@ -171,7 +171,7 @@ public function doNotShowThisAgain($cachable = false, $urlparams = []): void
171171
$user = ($userId === null)
172172
? $this->app->getIdentity()
173173
: $this->getUserFactory()->loadUserById($userId);
174-
$user = $user ?? $this->getUserFactory()->loadUserById(0);
174+
$user ??= $this->getUserFactory()->loadUserById(0);
175175

176176
if (!MfaHelper::canAddEditMethod($user)) {
177177
throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);

0 commit comments

Comments
 (0)