Make WordPress Core

Opened 4 months ago

Closed 4 months ago

#64488 closed enhancement (fixed)

Code Modernization: replace if isset() return with null coalescing

Reported by: soean's profile Soean Owned by: westonruter's profile westonruter
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch commit
Focuses: coding-standards Cc:

Description (last modified by westonruter)

In #63430 isset() ternary were replaced with null coalescing.

We also should replace if isset() return with null coalescing.

<?php
-        if (isset($this->items[$key])) {
-            return $this->items[$key];
-        }
-
-        return 'fallback value';
+        return $this->items[$key] ?? 'fallback value';

This is part of #58874.

Change History (7)

This ticket was mentioned in PR #10703 on WordPress/wordpress-develop by @Soean.


4 months ago
#1

  • Keywords has-patch added

#2 @sabernhardt
4 months ago

  • Summary changed from Coding Standards: replace if isset() return with null coalescing to Code Modernization: replace if isset() return with null coalescing
  • Type changed from defect (bug) to enhancement

#3 @westonruter
4 months ago

  • Milestone changed from Awaiting Review to 7.0
  • Owner set to westonruter
  • Status changed from new to reviewing

#4 @westonruter
4 months ago

  • Description modified (diff)

@westonruter commented on PR #10703:


4 months ago
#5

@Soean I found some additional opportunities in de042b59f67db0d6014be62bbe83070962ce8ad1. Take a look.

#6 @mukesh27
4 months ago

  • Keywords commit added

Mark ready for commit.

@westonruter will commit this soon.

#7 @westonruter
4 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 61470:

Code Modernization: Replace if statements with null coalescing operator.

Developed in https://github.com/WordPress/wordpress-develop/pull/10703

Follow-up to [61464], [61463], [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

Props soean, westonruter, mukesh27.
See #58874.
Fixes #64488.

Note: See TracTickets for help on using tickets.