diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml
new file mode 100644
index 0000000..0981ed9
--- /dev/null
+++ b/.github/workflows/pr.yaml
@@ -0,0 +1,57 @@
+name: pr
+
+on:
+ workflow_dispatch:
+ pull_request:
+ branches:
+ - master
+ types:
+ - opened
+ - reopened
+ - synchronize
+ - ready_for_review
+
+jobs:
+ phpstan-phpunit:
+ name: PHP Tests
+ strategy:
+ matrix:
+ php: [ '7.4', '8.3', '8.5' ]
+ runs-on: ubuntu-24.04
+ steps:
+ - name: Git Checkout
+ uses: actions/checkout@v3
+ - run: echo "The ${{ github.repository }} repository has been cloned to the runner."
+
+ - name: Composer install
+ uses: php-actions/composer@v6
+ with:
+ php_version: ${{matrix.php}}
+ - run: echo "Composer dependencies have been installed"
+
+ - name: Code Scanning
+ id: code-scanning
+ uses: php-actions/phpstan@v3
+ with:
+ php_version: ${{matrix.php}}
+ path: src/
+ configuration: "phpstan.neon"
+ memory_limit: "768M"
+ - run: echo "Stan tests complete"
+
+ - name: Unit Tests
+ id: unit-tests
+ uses: php-actions/phpunit@v3
+ env:
+ CREATE_SNAPSHOTS: false
+ with:
+ version: 9.6.29
+ php_version: ${{matrix.php}}
+ configuration: "phpunit.xml"
+ memory_limit: "768M"
+
+ - run: echo "Unit tests complete"
+
+ outputs:
+ code-scanning-status: ${{ steps.code-scanning.outcome }}
+ unit-tests-status: ${{ steps.unit-tests.outcome }}
diff --git a/.gitignore b/.gitignore
index de4a392..cfcb5c2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
/vendor
/composer.lock
+.phpunit.cache/
+.phpunit.result.cache
diff --git a/composer.json b/composer.json
index edd33be..9122d86 100644
--- a/composer.json
+++ b/composer.json
@@ -9,13 +9,14 @@
}
],
"require": {
- "php": ">=7.4",
+ "php": "^7.4|^8.0",
"packaged/helpers": "~1.0||^2.0",
"ext-ctype": "*"
},
"require-dev": {
"ext-gettext": "*",
- "phpunit/phpunit": "9.5.*"
+ "phpunit/phpunit": "^9.6",
+ "phpstan/phpstan": "^2.1"
},
"suggest": {
"ext-gettext": "*"
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 0000000..6274f72
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,11 @@
+parameters:
+ level: 7
+ paths:
+ - src
+ ignoreErrors:
+ -
+ identifiers:
+ - trait.unused
+ - "#^Unsafe usage of new static#"
+ - '#^Method [a-zA-Z0-9\\$\\_\\\\:\\(\\)]+ has parameter [a-zA-Z0-9\\$\\_\\\\:\\(\\)]+ with no value type specified in iterable type array\.$#'
+ - '#^Method [a-zA-Z0-9\\$\\_\\\\:\\(\\)]+ has parameter [a-zA-Z0-9\\$\\_\\\\:\\(\\)]+ with no type specified\.$#'
diff --git a/phpunit.xml b/phpunit.xml
index c08c8cf..9e1b5ac 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,25 +1,28 @@
-
+
+
+ src
+
+
tests
-
-
- src
-
-
diff --git a/src/Catalog/ArrayCatalog.php b/src/Catalog/ArrayCatalog.php
index e72f2dd..e085bf8 100644
--- a/src/Catalog/ArrayCatalog.php
+++ b/src/Catalog/ArrayCatalog.php
@@ -3,6 +3,9 @@
class ArrayCatalog implements MessageCatalog
{
+ /**
+ * @var array>
+ */
protected array $_data;
/**
@@ -28,8 +31,10 @@ public function getMessage($messageId): ?Message
{
$this->_data[$messageId] = [Message::DEFAULT_OPTION => $this->_data[$messageId]];
}
+
return new Message($this->_data[$messageId]);
}
+
return null;
}
}
diff --git a/src/Catalog/DynamicArrayCatalog.php b/src/Catalog/DynamicArrayCatalog.php
index 999cfbb..ca456f5 100644
--- a/src/Catalog/DynamicArrayCatalog.php
+++ b/src/Catalog/DynamicArrayCatalog.php
@@ -4,16 +4,24 @@
class DynamicArrayCatalog extends ArrayCatalog
{
/**
- * @var callable
+ * @var ?callable
*/
- protected $_translateCallback;
+ protected $_translateCallback = null;
+ /**
+ * @var array>
+ */
+ protected array $_data;
+
+ /**
+ * @return array>
+ */
public function getData(): array
{
return $this->_data;
}
- public function addMessage(string $messageId, array $options = [])
+ public function addMessage(string $messageId, array $options = []): self
{
$this->_data[$messageId] = $options;
return $this;
@@ -26,7 +34,7 @@ public function asPhpFile(bool $withNewLines = false): string
$content = ['_translateCallback;
+ $callback = $this->_translateCallback ?? null;
foreach($this->getData() as $mid => $options)
{
diff --git a/src/Catalog/Message.php b/src/Catalog/Message.php
index 9ce01bc..6c3bfdd 100644
--- a/src/Catalog/Message.php
+++ b/src/Catalog/Message.php
@@ -6,20 +6,20 @@ class Message
const DEFAULT_OPTION = '_';
const META_OPTION = '__meta';
+ /** @var array> */
+ protected array $_options;
/**
- * @var array
+ * @var string|int|null
*/
- protected array $_options;
-
- protected $_choice;
- protected $_choiceNumeric;
+ protected $_choice = null;
+ protected ?bool $_choiceNumeric = null;
public function __construct(array $options = [])
{
$this->_options = $options;
}
- public static function fromDefault($default)
+ public static function fromDefault($default): self
{
if(is_array($default))
{
@@ -29,7 +29,8 @@ public static function fromDefault($default)
if(is_scalar($default))
{
$matches = [];
- preg_match_all('/((\[[^\]]+\])?([^\|]+))+/m', $default, $matches);
+ preg_match_all('/((\[[^\]]+\])?([^\|]+))+/m', (string)$default, $matches);
+ /** @phpstan-ignore isset.offset */
if(isset($matches[3]))
{
foreach($matches[2] as $i => $key)
@@ -42,9 +43,11 @@ public static function fromDefault($default)
return $msg;
}
+ /** @return string[] */
public function getMeta(): array
{
- return $this->_options[self::META_OPTION] ?? [];
+ return isset($this->_options[self::META_OPTION]) && is_array($this->_options[self::META_OPTION])
+ ? $this->_options[self::META_OPTION] : [];
}
public function addOption($key, $value): self
@@ -53,12 +56,13 @@ public function addOption($key, $value): self
return $this;
}
+ /** @return array> */
public function getOptions(): array
{
return $this->_options;
}
- protected function _setChoice($choice = null)
+ protected function _setChoice($choice = null): void
{
if($choice === null)
{
@@ -86,17 +90,18 @@ protected function _selectChoice(): string
if($key === self::DEFAULT_OPTION)
{
$return = $v;
- if($this->_choice === null)
+ if($this->_choice === null && is_string($return))
{
return $return;
}
}
else if($this->_choiceMatches($key))
{
- return $v;
+ return is_string($v) ? $v : '';
}
}
- return $return;
+
+ return is_string($return) ? $return : '';
}
protected function _choiceMatches($optionKey): bool
@@ -111,10 +116,11 @@ protected function _choiceMatches($optionKey): bool
{
if($this->_choiceNumeric)
{
- if($key === 'n' || ((is_int($key) || ctype_digit($key)) && (int)$key === $this->_choice))
+ if($key === 'n' || ((ctype_digit($key)) && (int)$key === $this->_choice))
{
return true;
}
+
if(strpos($key, '..') > 0)
{
[$min, $max] = explode('..', $key);
diff --git a/src/Tools/Gettext/PoFile.php b/src/Tools/Gettext/PoFile.php
index 217c177..87b09a0 100644
--- a/src/Tools/Gettext/PoFile.php
+++ b/src/Tools/Gettext/PoFile.php
@@ -3,8 +3,9 @@
class PoFile
{
- protected $_language;
- protected $_headers = [
+ protected ?string $_language;
+ /** @var array */
+ protected array $_headers = [
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding' => '8bit',
@@ -14,7 +15,7 @@ class PoFile
/**
* @var PoTranslation[]
*/
- protected $_translations = [];
+ protected array $_translations = [];
public function __construct($language = null, $pluralForms = null)
{
@@ -22,24 +23,25 @@ public function __construct($language = null, $pluralForms = null)
$this->_setPluralForms($pluralForms);
}
- public function getHeaders()
+ /** @return array */
+ public function getHeaders(): array
{
return $this->_headers;
}
- protected function _setLanguage($lang)
+ protected function _setLanguage($lang): self
{
$this->_language = $lang;
$this->_headers['Language'] = $this->_language;
return $this;
}
- public function getLanguage()
+ public function getLanguage(): string
{
return $this->_language;
}
- public function addTranslation(PoTranslation ...$translations)
+ public function addTranslation(PoTranslation ...$translations): self
{
foreach($translations as $translation)
{
@@ -53,7 +55,8 @@ public function getTranslation($id): ?PoTranslation
return $this->_translations[$id] ?? null;
}
- public function getTranslations()
+ /** @return PoTranslation[] */
+ public function getTranslations(): array
{
return $this->_translations;
}
@@ -83,11 +86,11 @@ public static function fromString(string $poContent): ?PoFile
{
$trans = new static();
- $startingCases = ['#','msgid'];
+ $startingCases = ['#', 'msgid'];
- foreach($startingCases as $case)
+ foreach ($startingCases as $case)
{
- if(stristr($poContent, "\"\n{$case}"))
+ if (stristr($poContent, "\"\n{$case}"))
{
$poContent = str_replace("\"\n{$case}", "\"\n\n{$case}", $poContent);
}
@@ -95,20 +98,20 @@ public static function fromString(string $poContent): ?PoFile
$translations = explode("\n\n", $poContent);
$matches = [];
- if(preg_match('/\"Language: ([\w_]+).*\"/mi', $poContent, $matches))
+ if (preg_match('/\"Language: ([\w_]+).*\"/mi', $poContent, $matches))
{
$trans->_language = $matches[1];
}
- foreach($translations as $translation)
+ foreach ($translations as $translation)
{
- if(substr($translation, 0, 18) == 'msgid ""' . "\n" . 'msgstr ""')
+ if (substr($translation, 0, 18) == 'msgid ""' . "\n" . 'msgstr ""')
{
$trans->_headers = [];
$headers = explode("\n", substr($translation, 18));
- foreach($headers as $header)
+ foreach ($headers as $header)
{
$header = trim($header, '"');
- if($header)
+ if ($header)
{
[$hk, $hv] = explode(':', substr($header, -2) == '\n' ? substr($header, 0, -2) : $header, 2);
$trans->_headers[$hk] = trim($hv);
@@ -119,23 +122,24 @@ public static function fromString(string $poContent): ?PoFile
else
{
$converted = PoTranslation::fromString(trim($translation));
- if($converted !== null)
+ if ($converted !== null)
{
$trans->addTranslation($converted);
}
}
}
+
return $trans;
}
- public function removeTranslationByReference(string $ref)
+ public function removeTranslationByReference(string $ref): self
{
unset($this->_translations[$ref]);
return $this;
}
- public function removeTranslationByMsgId(string $msgId)
+ public function removeTranslationByMsgId(string $msgId): self
{
foreach($this->_translations as $reference => $translation)
{
@@ -148,7 +152,7 @@ public function removeTranslationByMsgId(string $msgId)
return $this;
}
- protected function _setPluralForms($pluralForms): PoFile
+ protected function _setPluralForms($pluralForms): self
{
if($pluralForms)
{
diff --git a/src/Tools/Gettext/PoTranslation.php b/src/Tools/Gettext/PoTranslation.php
index f23640a..b4eaccd 100644
--- a/src/Tools/Gettext/PoTranslation.php
+++ b/src/Tools/Gettext/PoTranslation.php
@@ -6,30 +6,38 @@
class PoTranslation
{
const FLAG_FUZZY = 'fuzzy';
-
- protected $_previous = [];
- protected $_id = '';
- protected $_comments = [];
- protected $_flags = [];
- protected $_references = [];
- protected $_extractedComments = [];
- protected $_context = '';
- protected $_singularSource = '';
- protected $_pluralSource = '';
- protected $_singularTranslation = '';
- protected $_pluralTranslation = '';
- protected $_additionalPluralTranslations = [];
+ /** @var string[] */
+ protected array $_previous = [];
+ protected string $_id = '';
+ /** @var string[] */
+ protected array $_comments = [];
+ /** @var string[] */
+ protected array $_flags = [];
+ /** @var string[] */
+ protected array $_references = [];
+ /** @var string[] */
+ protected array $_extractedComments = [];
+ protected string $_context = '';
+ protected string $_singularSource = '';
+ protected string $_pluralSource = '';
+ protected string $_singularTranslation = '';
+ protected string $_pluralTranslation = '';
+ /**
+ * @var array
+ */
+ protected array $_additionalPluralTranslations = [];
public function __construct($id)
{
$this->_id = $id;
}
- public function getId()
+ public function getId(): string
{
return $this->_id;
}
+ /** @return string[] */
public function getContent(): array
{
$lines = [];
@@ -89,12 +97,12 @@ public function getContent(): array
return $lines;
}
- public function __toString()
+ public function __toString(): string
{
return implode(PHP_EOL, $this->getContent());
}
- protected function _slash($text)
+ protected function _slash($text): string
{
$text = trim(addcslashes(stripslashes($text), '"'));
if(strpos($text, "\n") > 0)
@@ -109,16 +117,17 @@ public static function fromString(string $translationString): ?PoTranslation
$translation = new static('');
$lines = explode("\n", $translationString);
$currentCode = '';
- foreach($lines as $line)
+ foreach ($lines as $line)
{
$line = trim($line);
- if($line[0] == '#')
+
+ if ($line != '' && $line[0] == '#')
{
- if(!isset($line[1]))
+ if (strlen($line) < 2)
{
continue;
}
- switch($line[1])
+ switch ($line[1])
{
case '.':
$translation->_extractedComments[] = trim(substr($line, 2));
@@ -142,20 +151,35 @@ public static function fromString(string $translationString): ?PoTranslation
}
else
{
+ $content = '';
+
//Assume continuation
- if($line[0] == '"')
+ if ($line != '' && $line[0] == '"')
{
$content = $line;
}
else
{
- [$currentCode, $content] = explode(" ", $line, 2);
+ $elements = explode(" ", $line, 2);
+
+ if (count($elements) > 1)
+ {
+ $currentCode = array_shift($elements);
+ $content = array_shift($elements) ?: '';
+ }
}
+
$append = trim($content);
+
+ if ($append == '')
+ {
+ continue;
+ }
+
$starts = $append[0] === '"';
$ends = $append[strlen($append) - 1] === '"';
$append = substr($append, $starts ? 1 : 0, $ends ? -1 : null) . ($ends ? '' : PHP_EOL);
- switch($currentCode)
+ switch ($currentCode)
{
case 'msgid':
$translation->_singularSource .= $append;
@@ -174,10 +198,10 @@ public static function fromString(string $translationString): ?PoTranslation
$translation->_context .= $append;
break;
default:
- if(substr($currentCode, 0, 7) == 'msgstr[')
+ if (substr($currentCode, 0, 7) == 'msgstr[')
{
- $codeKey = rtrim(substr($currentCode, 7, ']'));
- if(!isset($translation->_additionalPluralTranslations[$codeKey]))
+ $codeKey = rtrim(substr($currentCode, 7), ']');
+ if (!isset($translation->_additionalPluralTranslations[$codeKey]))
{
$translation->_additionalPluralTranslations[$codeKey] = '';
}
@@ -192,19 +216,19 @@ public static function fromString(string $translationString): ?PoTranslation
$translation->_pluralTranslation = rtrim($translation->_pluralTranslation);
$translation->_pluralSource = rtrim($translation->_pluralSource);
$translation->_context = rtrim($translation->_context);
- foreach($translation->_additionalPluralTranslations as $k => $v)
+ foreach ($translation->_additionalPluralTranslations as $k => $v)
{
$translation->_additionalPluralTranslations[$k] = rtrim($v);
}
- if(!empty($translation->_references))
+ if (!empty($translation->_references))
{
$translation->_id = $translation->_references[0];
}
- if(empty($translation->_id) && $translation->_singularSource)
+ if (empty($translation->_id) && $translation->_singularSource)
{
- if(strpos($translation->_singularSource, " ") > -1)
+ if (strpos($translation->_singularSource, " ") > -1)
{
$translation->_id = TextIDGenerator::generate($translation->_singularSource);
}
@@ -217,9 +241,7 @@ public static function fromString(string $translationString): ?PoTranslation
return $translation->_id !== '' ? $translation : null;
}
- /**
- * @return array
- */
+ /** @return string[] */
public function getComments(): array
{
return $this->_comments;
@@ -236,9 +258,7 @@ public function setComments(array $comments): PoTranslation
return $this;
}
- /**
- * @return array
- */
+ /** @return string[] */
public function getReferences(): array
{
return $this->_references;
@@ -255,9 +275,7 @@ public function setReferences(array $developerComments): PoTranslation
return $this;
}
- /**
- * @return array
- */
+ /** @return string[] */
public function getExtractedComments(): array
{
return $this->_extractedComments;
@@ -313,14 +331,12 @@ public function hasFlag(string $flag): bool
return isset($this->_flags[$flag]);
}
+ /** @return string[] */
public function getFlags(): array
{
return $this->_flags;
}
- /**
- * @return string
- */
public function getContextString(): string
{
return $this->_context;
@@ -414,7 +430,7 @@ public function setPluralTranslation(string $pluralTranslation): PoTranslation
}
/**
- * @return array
+ * @return array
*/
public function getAdditionalPluralTranslations(): array
{
diff --git a/src/Tools/TextIDGenerator.php b/src/Tools/TextIDGenerator.php
index d22dce0..befb05e 100644
--- a/src/Tools/TextIDGenerator.php
+++ b/src/Tools/TextIDGenerator.php
@@ -6,7 +6,9 @@ class TextIDGenerator
protected int $_minWord = 3;
protected int $_prefixLength = 30;
protected bool $_appendBaseTime = false;
-
+ /**
+ * @var array
+ */
protected static array $_cache = [];
public function generateId(string $text): string
@@ -28,7 +30,7 @@ public function generateId(string $text): string
$long = str_word_count($text) > 3;
$result = strtolower(trim(substr(preg_replace('/[^\w]+/', '_', $text1), 0, $this->_prefixLength), '_')) . '_' .
($this->_appendBaseTime && $long ?
- base_convert(time(), 10, 36) : substr(md5($text), 0, $long ? 6 : 4) . ($long ? '_' . strlen($text) : ''));
+ base_convert(time() . "", 10, 36) : substr(md5($text), 0, $long ? 6 : 4) . ($long ? '_' . strlen($text) : ''));
static::$_cache[$text] = $result;
return $result;
diff --git a/src/Translators/AbstractTranslator.php b/src/Translators/AbstractTranslator.php
index 83c0c73..bbff531 100644
--- a/src/Translators/AbstractTranslator.php
+++ b/src/Translators/AbstractTranslator.php
@@ -18,6 +18,7 @@ protected function _applyReplacements(string $text, array $replacements = null):
return $text;
}
+ /** @var array */
protected static array $_pluralReplacements = [
'(s)' => 's',
'(fe)' => 'ves',
diff --git a/src/Translators/ReturnKeyTranslator.php b/src/Translators/ReturnKeyTranslator.php
index 8e39eec..c9cd484 100644
--- a/src/Translators/ReturnKeyTranslator.php
+++ b/src/Translators/ReturnKeyTranslator.php
@@ -2,22 +2,10 @@
namespace Packaged\I18n\Translators;
-use Packaged\I18n\Translatable;
-
-class ReturnKeyTranslator implements Translatable
+class ReturnKeyTranslator extends AbstractTranslator
{
public function _($msgId, $default, array $replacements = null, $choice = null): string
{
return $msgId;
}
-
- public function _p(string $msgId, string $singular, string $plural, int $n, array $replacements = null)
- {
- return $msgId;
- }
-
- public function _sp(string $msgId, string $simplePlural, int $n, array $replacements = null)
- {
- return $msgId;
- }
}
diff --git a/src/Translators/ReverseTranslator.php b/src/Translators/ReverseTranslator.php
index c6cc49d..4fa725f 100644
--- a/src/Translators/ReverseTranslator.php
+++ b/src/Translators/ReverseTranslator.php
@@ -10,7 +10,7 @@ public function _($msgId, $default, array $replacements = null, $choice = null):
return $this->_applyReplacements($this->_reverse(Message::fromDefault($default)->getText($choice)), $replacements);
}
- protected function _reverse($text)
+ protected function _reverse($text): string
{
return preg_replace_callback('/(?!\{)\b(\w+)\b(?!\})/', function ($str) { return strrev($str[0]); }, $text);
}
diff --git a/src/Translators/StarTranslator.php b/src/Translators/StarTranslator.php
index 798a2a9..18ab61e 100644
--- a/src/Translators/StarTranslator.php
+++ b/src/Translators/StarTranslator.php
@@ -8,9 +8,9 @@ class StarTranslator extends AbstractTranslator
const CHAR_STAR = '*';
const CHAR_HASH = '#';
- protected $_replacement;
+ protected string $_replacement = self::CHAR_STAR;
- public function __construct($style = self::CHAR_STAR)
+ public function __construct(string $style = self::CHAR_STAR)
{
$this->_replacement = $style;
}
@@ -23,7 +23,7 @@ public function _($msgId, $default, array $replacements = null, $choice = null):
);
}
- protected function _applyStars($text)
+ protected function _applyStars($text): string
{
return preg_replace_callback(
'/(?!\{)\b(\w+)\b(?!\})/',
diff --git a/src/Translators/TranslationLogger.php b/src/Translators/TranslationLogger.php
index 07dd45a..cfa86dc 100644
--- a/src/Translators/TranslationLogger.php
+++ b/src/Translators/TranslationLogger.php
@@ -6,6 +6,8 @@
class TranslationLogger extends AbstractTranslator
{
protected Translatable $_translator;
+
+ /** @var array> */
protected array $_translations = [];
const KEY_USAGES = 'usages';
@@ -18,7 +20,7 @@ public function __construct(Translatable $translator)
$this->_translator = $translator;
}
- public function _($msgId, $default, array $replacements = null, $choice = null): string
+ public function _(string $msgId, $default, array $replacements = null, $choice = null): string
{
if(!isset($this->_translations[$msgId]))
{
@@ -35,6 +37,7 @@ public function _($msgId, $default, array $replacements = null, $choice = null):
{
$this->_translations[$msgId][static::KEY_REPLACEMENTS] = true;
}
+
if($choice !== null)
{
$this->_translations[$msgId][static::KEY_CHOICES][] = $choice;
@@ -43,7 +46,10 @@ public function _($msgId, $default, array $replacements = null, $choice = null):
return $this->_translator->_($msgId, $default, $replacements, $choice);
}
- public function getTranslations()
+ /**
+ * @return array>
+ */
+ public function getTranslations(): array
{
return $this->_translations;
}
diff --git a/src/Translators/Translator.php b/src/Translators/Translator.php
index 15fe285..5a58b41 100644
--- a/src/Translators/Translator.php
+++ b/src/Translators/Translator.php
@@ -6,7 +6,15 @@
interface Translator extends Translatable
{
- public function _($msgId, $default, array $replacements = null, $choice = null): string;
+ /**
+ * @param string $msgId
+ * @param $default
+ * @param array|null $replacements
+ * @param mixed $choice
+ *
+ * @return string
+ */
+ public function _(string $msgId, $default, array $replacements = null, $choice = null): string;
public function _p(string $msgId, string $singular, string $plural, int $n, array $replacements = null): string;
diff --git a/src/Translators/WordJumbleTranslator.php b/src/Translators/WordJumbleTranslator.php
index 8596914..1b70d3c 100644
--- a/src/Translators/WordJumbleTranslator.php
+++ b/src/Translators/WordJumbleTranslator.php
@@ -9,19 +9,19 @@ class WordJumbleTranslator extends AbstractTranslator
const STYLE_SORT = 'sort';
const STYLE_SHUFFLE = 'shuffle';
- protected $_style;
+ protected string $_style;
- public function __construct($style = self::STYLE_SHUFFLE)
+ public function __construct(string $style = self::STYLE_SHUFFLE)
{
$this->_style = $style;
}
- public function _($msgId, $default, array $replacements = null, $choice = null): string
+ public function _(string $msgId, $default, array $replacements = null, $choice = null): string
{
return $this->_applyReplacements($this->_jumble(Message::fromDefault($default)->getText($choice)), $replacements);
}
- protected function _jumble($text)
+ protected function _jumble(string $text): string
{
return preg_replace_callback(
'/(?!\{)\b(\w+)\b(?!\})/',