Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ASCII.php for PHP 8.4 compatibility #105

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/voku/helper/ASCII.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
*
* @var string
*/
private static $REGEX_ASCII = "[^\x09\x10\x13\x0A\x0D\x20-\x7E]";

Check failure on line 184 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

@readonly property cannot have a default value.

/**
* bidirectional text chars
Expand All @@ -190,7 +190,7 @@
*
* @var array<int, string>
*/
private static $BIDI_UNI_CODE_CONTROLS_TABLE = [

Check failure on line 193 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

@readonly property cannot have a default value.
// LEFT-TO-RIGHT EMBEDDING (use -> dir = "ltr")
8234 => "\xE2\x80\xAA",
// RIGHT-TO-LEFT EMBEDDING (use -> dir = "rtl")
Expand Down Expand Up @@ -259,12 +259,12 @@
public static function charsArray(bool $replace_extra_symbols = false): array
{
if ($replace_extra_symbols) {
self::prepareAsciiAndExtrasMaps();

Check failure on line 262 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Impure call to method voku\helper\ASCII::prepareAsciiAndExtrasMaps() in pure method voku\helper\ASCII::charsArray().

return self::$ASCII_MAPS_AND_EXTRAS ?? [];
}

self::prepareAsciiMaps();

Check failure on line 267 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Impure call to method voku\helper\ASCII::prepareAsciiMaps() in pure method voku\helper\ASCII::charsArray().

return self::$ASCII_MAPS ?? [];
}
Expand All @@ -289,7 +289,7 @@
public static function charsArrayWithMultiLanguageValues(bool $replace_extra_symbols = false): array
{
/** @var array<string, array<string, array<int, string>>> */
static $CHARS_ARRAY = [];

Check failure on line 292 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Impure static variable in pure method voku\helper\ASCII::charsArrayWithMultiLanguageValues().
$cacheKey = '' . $replace_extra_symbols;

if (isset($CHARS_ARRAY[$cacheKey])) {
Expand Down Expand Up @@ -355,7 +355,7 @@

// init
/** @var array<string, array<string, array<string, string>|array{orig: string[], replace: string[]}>> */
static $CHARS_ARRAY = [];

Check failure on line 358 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Impure static variable in pure method voku\helper\ASCII::charsArrayWithOneLanguage().
$cacheKey = '' . $replace_extra_symbols . '-' . $asOrigReplaceArray;

// check static cache
Expand All @@ -364,7 +364,7 @@
}

if ($replace_extra_symbols) {
self::prepareAsciiAndExtrasMaps();

Check failure on line 367 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Impure call to method voku\helper\ASCII::prepareAsciiAndExtrasMaps() in pure method voku\helper\ASCII::charsArrayWithOneLanguage().

/** @noinspection DuplicatedCode */
if (isset(self::$ASCII_MAPS_AND_EXTRAS[$language])) {
Expand All @@ -390,7 +390,7 @@
}
}
} else {
self::prepareAsciiMaps();

Check failure on line 393 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Impure call to method voku\helper\ASCII::prepareAsciiMaps() in pure method voku\helper\ASCII::charsArrayWithOneLanguage().

/** @noinspection DuplicatedCode */
if (isset(self::$ASCII_MAPS[$language])) {
Expand Down Expand Up @@ -446,7 +446,7 @@
): array {
// init
/** @var array<string, array<string, string>|array{orig: string[], replace: string[]}> */
static $CHARS_ARRAY = [];

Check failure on line 449 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Impure static variable in pure method voku\helper\ASCII::charsArrayWithSingleLanguageValues().
$cacheKey = '' . $replace_extra_symbols . '-' . $asOrigReplaceArray;

if (isset($CHARS_ARRAY[$cacheKey])) {
Expand All @@ -454,7 +454,7 @@
}

if ($replace_extra_symbols) {
self::prepareAsciiAndExtrasMaps();

Check failure on line 457 in src/voku/helper/ASCII.php

View workflow job for this annotation

GitHub Actions / tests (7.4, basic)

Impure call to method voku\helper\ASCII::prepareAsciiAndExtrasMaps() in pure method voku\helper\ASCII::charsArrayWithSingleLanguageValues().

/** @noinspection AlterInForeachInspection */
/** @psalm-suppress PossiblyNullIterator - we use the prepare* methods here, so we don't get NULL here */
Expand Down Expand Up @@ -775,14 +775,14 @@
* @param string $str <p>The input string.</p>
* @param string $language [optional] <p>Language of the source string.
* (default is 'en') | ASCII::*_LANGUAGE_CODE</p>
* @param bool $remove_unsupported_chars [optional] <p>Whether or not to remove the
* @param bool $remove_unsupported_chars [optional] <p>Whether to remove the
* unsupported characters.</p>
* @param bool $replace_extra_symbols [optional] <p>Add some more replacements e.g. "£" with " pound
* ".</p>
* @param bool $use_transliterate [optional] <p>Use ASCII::to_transliterate() for unknown chars.</p>
* @param bool|null $replace_single_chars_only [optional] <p>Single char replacement is better for the
* performance, but some languages need to replace more then one char
* at the same time. | NULL === auto-setting, depended on the
* @param bool $replace_single_chars_only [optional] <p>Single char replacement is better for the
* performance, but some languages need to replace more than one char
* at the same time. If FALSE === auto-setting, depended on the
* language</p>
*
* @psalm-pure
Expand All @@ -798,7 +798,7 @@
bool $remove_unsupported_chars = true,
bool $replace_extra_symbols = false,
bool $use_transliterate = false,
bool $replace_single_chars_only = null
bool $replace_single_chars_only = false
): string {
if ($str === '') {
return '';
Expand Down
Loading