diff options
| author | Appleman1234 <applemansigloo@gmail.com> | 2022-09-25 13:30:13 +1000 |
|---|---|---|
| committer | Appleman1234 <applemansigloo@gmail.com> | 2022-09-25 13:30:13 +1000 |
| commit | 2c69095a1edf7474073451285238659d0f62ce3f (patch) | |
| tree | 5dee476605402c66dc2853d0836b29f6aedae62b /tools/inc/lib/jsgettext/JSParser.php | |
| parent | e9a61e2fbbd930eaa80d6a5f33420cedc59d748c (diff) | |
PHP8.1 fixes from Rector
Diffstat (limited to 'tools/inc/lib/jsgettext/JSParser.php')
| -rw-r--r-- | tools/inc/lib/jsgettext/JSParser.php | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/tools/inc/lib/jsgettext/JSParser.php b/tools/inc/lib/jsgettext/JSParser.php index adba59bc..739d1195 100644 --- a/tools/inc/lib/jsgettext/JSParser.php +++ b/tools/inc/lib/jsgettext/JSParser.php @@ -4,9 +4,9 @@ class JSParser { protected $content; protected $keywords; - protected $regs = array(); + protected $regs = []; protected $regsCounter = 0; - protected $strings = array(); + protected $strings = []; protected $stringsCounter = 0; protected function _extractRegs($match) { @@ -23,16 +23,12 @@ class JSParser { } protected function importRegExps($input) { $regs = $this->regs; - return preg_replace_callback("#<<reg(\d+)>>#", function ($match) use($regs) { - return $regs[$match[1]]; - }, $input); + return preg_replace_callback("#<<reg(\d+)>>#", fn($match) => $regs[$match[1]], $input); } protected function importStrings($input) { $strings = $this->strings; - return preg_replace_callback("#<<s(\d+)>>#", function ($match) use($strings) { - return $strings[$match[1]]; - }, $input); + return preg_replace_callback("#<<s(\d+)>>#", fn($match) => $strings[$match[1]], $input); } public function __construct($file, $keywords = '_') { @@ -46,15 +42,12 @@ class JSParser { // extract reg exps $output = preg_replace_callback( '# ( / (?: (?>[^/\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\/ )+ (?<!\\\\)/ ) [a-z]* \b #ix', - array($this, '_extractRegs'), $output + $this->_extractRegs(...), $output ); // extract strings $output = preg_replace_callback( - array( - '# " ( (?: (?>[^"\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\" )* ) (?<!\\\\)" #ix', - "# ' ( (?: (?>[^'\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\' )* ) (?<!\\\\)' #ix" - ), array($this, '_extractStrings'), $output + ['# " ( (?: (?>[^"\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\" )* ) (?<!\\\\)" #ix', "# ' ( (?: (?>[^'\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\' )* ) (?<!\\\\)' #ix"], $this->_extractStrings(...), $output ); // delete line comments @@ -64,13 +57,11 @@ class JSParser { $output = preg_replace('#/\*(.*?)\*/#is', '', $output); $strings = $this->strings; - $output = preg_replace_callback("#<<s(\d+)>>#", function($match) use($strings) { - return $strings[$match[1]]; - }, $output); + $output = preg_replace_callback("#<<s(\d+)>>#", fn($match) => $strings[$match[1]], $output); $keywords = implode('|', $this->keywords); - $strings = array(); + $strings = []; // extract func calls preg_match_all( @@ -78,15 +69,15 @@ class JSParser { $output, $matches, PREG_SET_ORDER ); - foreach ($matches as $m) $strings[] = stripslashes($m[1]); + foreach ($matches as $m) $strings[] = stripslashes((string) $m[1]); - $matches = array(); + $matches = []; preg_match_all( "# (?:$keywords) \(\\ *' ( (?: (?>[^'\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\' )* ) (?<!\\\\)'\\ *\) #ix", $output, $matches, PREG_SET_ORDER ); - foreach ($matches as $m) $strings[] = stripslashes($m[1]); + foreach ($matches as $m) $strings[] = stripslashes((string) $m[1]); return $strings; } |
