From 10ca60baee4a202e83c734dfaa64eb23bcedd046 Mon Sep 17 00:00:00 2001
From: Colin Stewart <79332690+costdev@users.noreply.github.com>
Date: Wed, 16 Jul 2025 21:36:55 +0100
Subject: [PATCH] Make `compat.php` compliant with the coding standard. (#165)
---
inc/compatibility/compat.php | 22 +++++++++++-----------
phpcs.xml.dist | 3 ++-
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/inc/compatibility/compat.php b/inc/compatibility/compat.php
index 890a261..a9c99b1 100644
--- a/inc/compatibility/compat.php
+++ b/inc/compatibility/compat.php
@@ -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().
*
@@ -117,7 +117,7 @@ if ( ! function_exists( 'mb_substr' ) ) :
function mb_substr( $string, $start, $length = null, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound
return _mb_substr( $string, $start, $length, $encoding );
}
-endif;
+}
// If _mb_substr already loaded.
if ( ! function_exists( '_mb_substr' ) ) {
@@ -174,11 +174,11 @@ if ( ! function_exists( '_mb_substr' ) ) {
| \xF4[\x80-\x8F][\x80-\xBF]{2}
)/x';
- // Start with 1 element instead of 0 since the first thing we do is pop.
- $chars = array( '' );
+ // Start with 1 element instead of 0 since the first thing we do is pop.
+ $chars = [ '' ];
- do {
- // We had some string left over from the last round, but we counted it in that last round.
+ do {
+ // We had some string left over from the last round, but we counted it in that last round.
array_pop( $chars );
/*
@@ -190,13 +190,13 @@ if ( ! function_exists( '_mb_substr' ) ) {
$chars = array_merge( $chars, $pieces );
// 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 ) );
}
}
-if ( ! function_exists( 'mb_strlen' ) ) :
+if ( ! function_exists( '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
return _mb_strlen( $string, $encoding );
}
-endif;
+}
// If _mb_strlen is already loaded.
if ( ! function_exists( '_mb_strlen' ) ) {
@@ -278,7 +278,7 @@ if ( ! function_exists( '_mb_strlen' ) ) {
$count += count( $pieces );
// 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.
return --$count;
@@ -375,7 +375,7 @@ if ( ! function_exists( 'array_is_list' ) ) {
* @return bool True if array is a list, false otherwise.
*/
function array_is_list( $arr ) {
- if ( ( array() === $arr ) || ( array_values( $arr ) === $arr ) ) {
+ if ( ( [] === $arr ) || ( array_values( $arr ) === $arr ) ) {
return true;
}
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 82bb360..19b7a08 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -34,7 +34,6 @@
inc/updater/class-lite\.php
- inc/compatibility/compat\.php
languages/*
@@ -56,6 +55,7 @@
+ inc/compatibility/compat\.php
inc/icons/svg\.php
@@ -70,6 +70,7 @@
plugin\.php
+ inc/compatibility/compat\.php
inc/icons/svg\.php
tests/phpunit/bootstrap\.php