Skip to content

Commit

Permalink
NamingConventions::isEqual(): minor simplification
Browse files Browse the repository at this point in the history
No need to "translate" the ASCII characters from uppercase to lowercase, the PHP native `strcasecmp()` function can do the comparison correctly as it only compares ASCII letters in a case-insensitive way.

Ref: https://www.php.net/manual/en/function.strcasecmp.php
  • Loading branch information
jrfnl committed Mar 16, 2024
1 parent 23ddcad commit c6fabf3
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions PHPCSUtils/Utils/NamingConventions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ final class NamingConventions
/**
* Uppercase A-Z.
*
* @since 1.0.0
* @since 1.0.0
* @deprecated 1.0.10
*
* @var string
*/
Expand All @@ -49,7 +50,8 @@ final class NamingConventions
/**
* Lowercase a-z.
*
* @since 1.0.0
* @since 1.0.0
* @deprecated 1.0.10
*
* @var string
*/
Expand Down Expand Up @@ -108,10 +110,7 @@ public static function isEqual($nameA, $nameB)
return true;
}

// OK, so these may be different names or they may be the same name with case differences.
$nameA = \strtr($nameA, self::AZ_UPPER, self::AZ_LOWER);
$nameB = \strtr($nameB, self::AZ_UPPER, self::AZ_LOWER);

return ($nameA === $nameB);
// Comparing via strcasecmp will only compare ASCII letters case-insensitively.
return (strcasecmp($nameA, $nameB) === 0);
}
}

0 comments on commit c6fabf3

Please sign in to comment.