Make WordPress Core

Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#58139 closed enhancement (fixed)

Use strict type comparison in wp-admin/includes/class-wp-ms-sites-list-table.php

Reported by: mujuonly's profile mujuonly Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.3 Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: has-patch
Focuses: multisite Cc:

Description

Use === instead of == in wp-admin/includes/class-wp-ms-sites-list-table.php

Change History (9)

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


17 months ago
#1

  • Keywords has-patch added; needs-patch removed

Use === instead of == in wp-admin/includes/class-wp-ms-sites-list-table.php

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

#2 @audrasjb
17 months ago

  • Version 6.2 deleted

Thanks for opening this ticket and for the PR.

I have not looked deeply into this, but are we sure that $blog['deleted'], $blog['archived'] and $blog['spam'] are string type? Shouldn't we cast them into a string?

#3 follow-up: @jankyz
17 months ago

Even if those are strings this condition checks if each has value '1' it means true

cast to (string) won't change anything here

<?php
if ( '1' == $blog['deleted'] ) {}

we can simply reverse the condition and use ===

<?php
if ( $blog['deleted'] === '1' ) {}

#4 in reply to: ↑ 3 @krupalpanchal
17 months ago

Replying to jankyz:

Even if those are strings this condition checks if each has value '1' it means true

cast to (string) won't change anything here

<?php
if ( '1' == $blog['deleted'] ) {}

we can simply reverse the condition and use ===

<?php
if ( $blog['deleted'] === '1' ) {}

It is good to use the Yoda condition here according to standards.

#5 @SergeyBiryukov
17 months ago

Thanks for the PR! I have confirmed that these values are indeed strings as returned from get_sites() via WP_MS_Sites_List_Table::prepare_items().

They match the WP_Site class properties of the same name, which are also defined as numeric strings, '1' or '0', for compatibility reasons.

#6 @SergeyBiryukov
17 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 55656:

Coding Standards: Use strict comparison in wp-admin/includes/class-wp-ms-sites-list-table.php.

Includes minor code layout fixes for better readability.

Follow-up to [12603], [32630], [32755], [46441].

Props mujuonly, audrasjb, jankyz, krupalpanchal, SergeyBiryukov.
Fixes #58139.

#7 @SergeyBiryukov
17 months ago

  • Milestone changed from Awaiting Review to 6.3

#8 @SergeyBiryukov
17 months ago

  • Summary changed from Strict type comparison to Use strict type comparison in wp-admin/includes/class-wp-ms-sites-list-table.php

@SergeyBiryukov commented on PR #4334:


17 months ago
#9

Thanks for the PR! Merged in r55656.

Note: See TracTickets for help on using tickets.