Make compat.php compliant with the coding standard. (#165)

This commit is contained in:
Colin Stewart 2025-07-16 21:36:55 +01:00 committed by GitHub
parent 2b858dc3c2
commit 10ca60baee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 12 deletions

View file

@ -98,7 +98,7 @@ if ( ! function_exists( '_is_utf8_charset' ) ) {
} }
} }
if ( ! function_exists( 'mb_substr' ) ) : if ( ! function_exists( 'mb_substr' ) ) {
/** /**
* Compat function to mimic mb_substr(). * Compat function to mimic mb_substr().
* *
@ -117,7 +117,7 @@ if ( ! function_exists( 'mb_substr' ) ) :
function mb_substr( $string, $start, $length = null, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound function mb_substr( $string, $start, $length = null, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound
return _mb_substr( $string, $start, $length, $encoding ); return _mb_substr( $string, $start, $length, $encoding );
} }
endif; }
// If _mb_substr already loaded. // If _mb_substr already loaded.
if ( ! function_exists( '_mb_substr' ) ) { if ( ! function_exists( '_mb_substr' ) ) {
@ -174,11 +174,11 @@ if ( ! function_exists( '_mb_substr' ) ) {
| \xF4[\x80-\x8F][\x80-\xBF]{2} | \xF4[\x80-\x8F][\x80-\xBF]{2}
)/x'; )/x';
// Start with 1 element instead of 0 since the first thing we do is pop. // Start with 1 element instead of 0 since the first thing we do is pop.
$chars = array( '' ); $chars = [ '' ];
do { do {
// We had some string left over from the last round, but we counted it in that last round. // We had some string left over from the last round, but we counted it in that last round.
array_pop( $chars ); array_pop( $chars );
/* /*
@ -190,13 +190,13 @@ if ( ! function_exists( '_mb_substr' ) ) {
$chars = array_merge( $chars, $pieces ); $chars = array_merge( $chars, $pieces );
// If there's anything left over, repeat the loop. // If there's anything left over, repeat the loop.
} while ( count( $pieces ) > 1 && $str = array_pop( $pieces ) ); } while ( count( $pieces ) > 1 && $str = array_pop( $pieces ) ); // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
return implode( '', array_slice( $chars, $start, $length ) ); return implode( '', array_slice( $chars, $start, $length ) );
} }
} }
if ( ! function_exists( 'mb_strlen' ) ) : if ( ! function_exists( 'mb_strlen' ) ) {
/** /**
* Compat function to mimic mb_strlen(). * Compat function to mimic mb_strlen().
* *
@ -212,7 +212,7 @@ if ( ! function_exists( 'mb_strlen' ) ) :
function mb_strlen( $string, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound function mb_strlen( $string, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound
return _mb_strlen( $string, $encoding ); return _mb_strlen( $string, $encoding );
} }
endif; }
// If _mb_strlen is already loaded. // If _mb_strlen is already loaded.
if ( ! function_exists( '_mb_strlen' ) ) { if ( ! function_exists( '_mb_strlen' ) ) {
@ -278,7 +278,7 @@ if ( ! function_exists( '_mb_strlen' ) ) {
$count += count( $pieces ); $count += count( $pieces );
// If there's anything left over, repeat the loop. // If there's anything left over, repeat the loop.
} while ( $str = array_pop( $pieces ) ); } while ( $str = array_pop( $pieces ) ); // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
// Fencepost: preg_split() always returns one extra item in the array. // Fencepost: preg_split() always returns one extra item in the array.
return --$count; return --$count;
@ -375,7 +375,7 @@ if ( ! function_exists( 'array_is_list' ) ) {
* @return bool True if array is a list, false otherwise. * @return bool True if array is a list, false otherwise.
*/ */
function array_is_list( $arr ) { function array_is_list( $arr ) {
if ( ( array() === $arr ) || ( array_values( $arr ) === $arr ) ) { if ( ( [] === $arr ) || ( array_values( $arr ) === $arr ) ) {
return true; return true;
} }

View file

@ -34,7 +34,6 @@
<!-- Exclude third-party dependencies --> <!-- Exclude third-party dependencies -->
<exclude-pattern>inc/updater/class-lite\.php</exclude-pattern> <exclude-pattern>inc/updater/class-lite\.php</exclude-pattern>
<exclude-pattern>inc/compatibility/compat\.php</exclude-pattern>
<!-- Exclude language files --> <!-- Exclude language files -->
<exclude-pattern>languages/*</exclude-pattern> <exclude-pattern>languages/*</exclude-pattern>
@ -56,6 +55,7 @@
</rule> </rule>
<rule ref="HM.Functions.NamespacedFunctions.MissingNamespace"> <rule ref="HM.Functions.NamespacedFunctions.MissingNamespace">
<exclude-pattern>inc/compatibility/compat\.php</exclude-pattern>
<exclude-pattern>inc/icons/svg\.php</exclude-pattern> <exclude-pattern>inc/icons/svg\.php</exclude-pattern>
</rule> </rule>
@ -70,6 +70,7 @@
<!-- Exclude some files from the side effects rules --> <!-- Exclude some files from the side effects rules -->
<rule ref="PSR1.Files.SideEffects"> <rule ref="PSR1.Files.SideEffects">
<exclude-pattern>plugin\.php</exclude-pattern> <exclude-pattern>plugin\.php</exclude-pattern>
<exclude-pattern>inc/compatibility/compat\.php</exclude-pattern>
<exclude-pattern>inc/icons/svg\.php</exclude-pattern> <exclude-pattern>inc/icons/svg\.php</exclude-pattern>
<exclude-pattern>tests/phpunit/bootstrap\.php</exclude-pattern> <exclude-pattern>tests/phpunit/bootstrap\.php</exclude-pattern>
</rule> </rule>