Make WordPress Core

Opened 5 weeks ago

Closed 5 weeks ago

#66162 closed enhancement (fixed)

Code Quality: Fix redundant null coalescing in block style variation

Reported by: arshidkv12 Owned by: westonruter
Priority: normal Milestone: 7.2
Component: General Version:
Severity: normal Keywords: has-patch commit
Cc: Focuses:

Description (last modified by arshidkv12)

This change removes the redundant null coalescing operator from wp_get_block_style_variation_name_from_class() in src/wp-includes/block-supports/block-style-variations.php.

The preg_match_all() always initializes $matches[1] as an array, even when no matches are found, so ?? null is unnecessary. The corresponding PHPStan baseline entry is also removed.

Change History (7)

This ticket was mentioned in ​PR #13673 on ​WordPress/wordpress-develop by ​@arshidkv12.


5 weeks ago
#1

  • Keywords has-patch has-unit-tests added

This change removes the redundant null coalescing operator from wp_get_block_style_variation_name_from_class() in src/wp-includes/block-supports/block-style-variations.php. preg_match_all() always initializes $matches[1] as an array, even when no matches are found, so ?? null is unnecessary. The corresponding PHPStan baseline entry is also removed.

Trac ticket: https://core.trac.wordpress.org/ticket/66162

Use of AI Tools

AI assistance: Yes
Tool(s): ChatGPT
Model(s): GPT-5.6 Luna
Used for: Reviewing the PHPStan warning and discussing possible implementation approaches; the final change and code were reviewed and edited by me.

#2 @arshidkv12
5 weeks ago

  • Description modified (diff)

#3 @arshidkv12
5 weeks ago

  • Description modified (diff)

​@arshidkv12 commented on ​PR #13673:


5 weeks ago
#4

Thanks @arshidkv12 for the PR!

You are welcome

#5 @mukesh27
5 weeks ago

  • Keywords commit added; has-unit-tests removed
  • Owner set to westonruter
  • Status new → reviewing

#6 @westonruter
5 weeks ago

@arshidkv12 Thank you. This is another ticket which you could bypass creating a ticket, and just open a PR targeting #65817.

#7 @westonruter
5 weeks ago

  • Resolution → fixed
  • Status reviewing → closed

In 63890:

Code Quality: Remove a redundant null coalescing operator.

In wp_get_block_style_variation_name_from_class(), the ?? null fallback after preg_match_all() never applied, since $matches[1] is always populated with an array, even when there are no matches or the call fails. The now-empty nullCoalesce.offset PHPStan baseline is removed accordingly. The function's types are also refined: the parameter is documented as string|null, a native ?array return type is added, and a conditional return type narrows the result to list<non-empty-string> when a string is passed.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13673.
Follow-up to r58264, r63023.

Props arshidkv12, westonruter, mukesh27.
See #65817.
Fixes #66162.

Note: See TracTickets for help on using tickets.