summaryrefslogtreecommitdiff
path: root/tools/inc/lib/jsgettext/PoeditParser.php
diff options
context:
space:
mode:
authorAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:30:13 +1000
committerAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:30:13 +1000
commit2c69095a1edf7474073451285238659d0f62ce3f (patch)
tree5dee476605402c66dc2853d0836b29f6aedae62b /tools/inc/lib/jsgettext/PoeditParser.php
parente9a61e2fbbd930eaa80d6a5f33420cedc59d748c (diff)
PHP8.1 fixes from Rector
Diffstat (limited to 'tools/inc/lib/jsgettext/PoeditParser.php')
-rw-r--r--tools/inc/lib/jsgettext/PoeditParser.php25
1 files changed, 12 insertions, 13 deletions
diff --git a/tools/inc/lib/jsgettext/PoeditParser.php b/tools/inc/lib/jsgettext/PoeditParser.php
index eebd816e..0fbe04e6 100644
--- a/tools/inc/lib/jsgettext/PoeditParser.php
+++ b/tools/inc/lib/jsgettext/PoeditParser.php
@@ -4,17 +4,16 @@ require_once 'PoeditString.php';
class PoeditParser {
- protected $file;
protected $header = '';
- protected $strings = array();
+ protected $strings = [];
protected function _fixQuotes($str) {
- return stripslashes($str);
+ return stripslashes((string) $str);
}
- public function __construct($file) {
- $this->file = $file;
- }
+ public function __construct(protected $file)
+ {
+ }
public function parse() {
$contents = file_get_contents($this->file);
@@ -26,13 +25,13 @@ class PoeditParser {
foreach ($parts as $part) {
// parse comments
- $comments = array();
- preg_match_all('#^\\#: (.*?)$#m', $part, $matches, PREG_SET_ORDER);
+ $comments = [];
+ preg_match_all('#^\\#: (.*?)$#m', (string) $part, $matches, PREG_SET_ORDER);
foreach ($matches as $m) $comments[] = $m[1];
- $isFuzzy = preg_match('#^\\#, fuzzy$#im', $part) ? true : false;
+ $isFuzzy = preg_match('#^\\#, fuzzy$#im', (string) $part) ? true : false;
- preg_match_all('# ^ (msgid|msgstr)\ " ( (?: (?>[^"\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\" )* ) (?<!\\\\)" $ #ixm', $part, $matches2, PREG_SET_ORDER);
+ preg_match_all('# ^ (msgid|msgstr)\ " ( (?: (?>[^"\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\" )* ) (?<!\\\\)" $ #ixm', (string) $part, $matches2, PREG_SET_ORDER);
$k = $this->_fixQuotes($matches2[0][2]);
$v = !empty($matches2[1][2]) ? $this->_fixQuotes($matches2[1][2]) : '';
@@ -58,11 +57,11 @@ class PoeditParser {
}
public function getJSON() {
- $str = array();
+ $str = [];
foreach ($this->strings as $s) {
if ($s->value) $str[$s->key] = $s->value;
}
- return json_encode($str);
+ return json_encode($str, JSON_THROW_ON_ERROR);
}
public function toJSON($outputFilename, $varName = 'l10n') {
@@ -75,7 +74,7 @@ class PoeditParser {
foreach ($this->strings as $str) {
$data .= $str;
}
- return file_put_contents($filename ? $filename : $this->file, $data) !== false;
+ return file_put_contents($filename ?: $this->file, $data) !== false;
}
}